Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87784
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <fomcl@yahoo.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'configure': 0.05; 'cpython': 0.05; 'preferably': 0.05; 'true,': 0.05; 'subject:Python': 0.06; 'finished,': 0.07; 'interpreter.': 0.07; 'subject:file': 0.07; 'tries': 0.07; 'wednesday,': 0.07; '2.3,': 0.09; 'counting': 0.09; 'exception.': 0.09; 'exits': 0.09; 'scripts,': 0.09; 'subject:script': 0.09; 'runs': 0.10; '"r")': 0.16; '"w")': 0.16; '(when': 0.16; '>>on': 0.16; '>on': 0.16; 'argument,': 0.16; 'cet': 0.16; 'garbage': 0.16; 'proc': 0.16; 'skip:> 20': 0.16; 'stdout': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; 'all.': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'wed,': 0.18; 'file,': 0.19; 'possible,': 0.19; 'thu,': 0.19; '(the': 0.22; 'command': 0.22; '>>>': 0.22; 'circular': 0.24; 'header:Received:8': 0.24; 'java': 0.24; 'references': 0.26; 'second': 0.26; 'gets': 0.27; 'to:2**1': 0.27; 'idea': 0.28; 'am,': 0.29; 'to:no real name:2**1': 0.29; "doesn't": 0.30; 'robert': 0.30; 'code': 0.31; 'about.': 0.31; 'block,': 0.31; "d'aprano": 0.31; 'once,': 0.31; 'steven': 0.31; 'file': 0.32; 'probably': 0.32; 'stuff': 0.32; 'run': 0.32; 'open': 0.33; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'are,': 0.36; 'object,': 0.36; 'skip:> 10': 0.36; 'method': 0.36; 'charset :us-ascii': 0.36; 'skip:- 20': 0.37; 'to:addr:python-list': 0.38; 'files': 0.38; 'skip:. 10': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'received:67.195': 0.60; 'received:98.137': 0.60; 'free': 0.61; 'break': 0.61; 'march': 0.61; 'save': 0.62; 'name': 0.63; 'soon': 0.63; 'between': 0.67; 'close': 0.67; 'mar': 0.68; 'received:gq1.yahoo.com': 0.68; 'received:mail.gq1.yahoo.com': 0.68; '2015': 0.84; '3.4': 0.84; 'amazed': 0.84; 'received:bullet.mail.gq1.yahoo.com': 0.84; 'involved.': 0.91; 'differences': 0.93; 'dirty': 0.93; 'hand,': 0.93 |
| X-Yahoo-Newman-Property | ymail-4 |
| X-Yahoo-Newman-Id | 555428.67238.bm@omp1038.mail.gq1.yahoo.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1426864556; bh=08qb4Jzmo8UGjgUEonYXyKNF5xYaOOrdQkOVyy42Rzg=; h=Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=SU+QGmm74MIa83rRg+kEOnRY98WAmmAjk9gI1Nl+1MIpotlOsCPMRdtac0/wu+7raXno1lvn9DFkzgyzHEe7cffjf/fa0zpf5j8tSv4DMf/cViBivQKft6FVON/2NNW57od5HReYnGCmjSai4EhBWxLckP/Y+k2ol6UyV8RU4NY= |
| X-YMail-OSG | YgPHIjgVM1lWqvjcvyxNBisikhHuDuaW3eVUK1A8FV1CUiN SBsFDWzgJAPdtuT6N_XD2yxBFjd_qbbPMyzV40FKREXjT66VYxcuv.wgJNAf jLEIbMzPzJsR5C2qRys.7nXyQKoFuDlZlKjddxHlwSRkE8nM.lbKrpTHXnRI YH46.AQ2D9PsAo_Gv9DRahP6v6HPBRaPgjCeP71_klFwAcILP2TH3kag26yj 6VliaJoecIeaJm0j51rUZaSyBvN_7NLqwOX5yKMpU37yqrzHJtI470UM.SRz FUDocO8zCDdaY6lm12VAemCJbj9RGhIN5kbT1o1rhb3CoR_NfD9gPgrnk6eT xTRXmCVSmIt6CZp5oeEemmMPL1S.WrMx_2VDK.ca2J.N2K4oXPjcd3TAiCxe 6Zw6Zdn5o39KN6BBdDmB0vAxKOdlv.qdOyMzaZ2RlHllLMhmO3RKtBm1qYk6 YegQ1PRlXkv0pGzJaOxlsiAwHYo95t_.mZ0hkLgTGwQhxjLFLKzqiKeQLcST TewyhctPSAIJ0ua0UWPSfhQyp5fiCHn6gxdGnioCLHIMJXif5LsBPKOZtnId unjVf24wWEsgTln4R9djI2GXWtgogRyv61u0clX5gEX2oyPl3y3Wlxom_cwK zmoW.c_YglU0- |
| X-Rocket-MIMEInfo | 002.001, Ci0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tDQpPbiBUaHUsIE1hciAxOSwgMjAxNSAxMjoxNiBBTSBDRVQgU3RldmVuIEQnQXByYW5vIHdyb3RlOg0KDQo.T24gVGh1LCAxOSBNYXIgMjAxNSAwNzoyMiBhbSwgQWxiZXJ0LUphbiBSb3NrYW0gd3JvdGU6DQo.DQo.PiANCj4.IC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0NCj4.IE9uIFdlZCwgTWFyIDE4LCAyMDE1IDc6MDYgUE0gQ0VUIFJ1c3RvbSBNb2R5IHdyb3RlOg0KPj4gDQo.Pk9uIFdlZG5lc2RheSwgTWFyY2ggMTgsIDIwMTUgYXQgODoxMjoBMAEBAQE- |
| X-Mailer | YahooMailWebService/0.8.203.740 |
| Date | Fri, 20 Mar 2015 08:15:56 -0700 |
| From | Albert-Jan Roskam <fomcl@yahoo.com> |
| Subject | Re: Python script output in file |
| To | steve+comp.lang.python@pearwood.info, python-list@python.org |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.40.1426864851.10327.python-list@python.org> (permalink) |
| Lines | 63 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1426864851 news.xs4all.nl 2843 [2001:888:2000:d::a6]:45387 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:87784 |
Show key headers only | View raw
-----------------------------
On Thu, Mar 19, 2015 12:16 AM CET Steven D'Aprano wrote:
>On Thu, 19 Mar 2015 07:22 am, Albert-Jan Roskam wrote:
>
>>
>> ----------------------------
>> On Wed, Mar 18, 2015 7:06 PM CET Rustom Mody wrote:
>>
>>On Wednesday, March 18, 2015 at 8:12:12 PM UTC+5:30, Robert Clove wrote:
>>> ./my_eth_script.pl eth0 M > a.txt
>>>
>>> How can i run this command with subprocess.popen
>>
>>Something like this I guess?
>>
>>> proc = Popen("cat", shell=True, stdout=open(inname, "w"),
>>> stdin=open(outname,"r"))
>>
>>
>> How will the file object associated with in name be closed? (When is
>> close() method called?
>
>Depends on the interpreter.
>
>CPython (the one you are probably using) will notice immediately the proc
>object goes out of scope and is garbage-collected. That will free up the
>Popen stdout argument, which will garbage collect the file object, which
>will close the inname file immediately.
>
>Assuming there are no circular references involved. If there are, then the
>file won't be closed until the second garbage collector gets to run. It
>will break the circular reference and close the file, but there is no
>promise as to how often it will run. The user can configure how often it
>runs and even whether it runs at all.
>
>On the other hand, Jython will garbage-collect the file object, but the file
>itself may remain open until your code exits, and only be closed on
>interpreter-shutdown. Since the operator system probably has limits on how
>many files you can have open at once, you might actually run out.
>
>For quick and dirty scripts, it doesn't matter, but best practice is to
>explicitly close your files as soon as possible, preferably with a `with`
>statement:
>
>
># I think inname and outname are reversed...
>with open(inname, "w") as outfile, open(outname, "r") as infile:
> proc = Popen("cat", shell=True, stdout=outfile, stdin=infile)
> # do stuff with proc
> # when finished, save the stuff you care about
> result = ...
>
>print(result)
>
>
>Outside of the `with` block, proc's stdout and stdin will be automatically
>closed, even if the block exits with an exception.
Thanks, this is indeed what I was thinking about. I had no idea about the GC differences between cpython and jython (reference counting vs true, java GC). I am amazed that jython is just a version 2.3, is it tries to look like cpython 2.3! But perhaps they're about to jump to 3.4
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Python script output in file Albert-Jan Roskam <fomcl@yahoo.com> - 2015-03-20 08:15 -0700
csiph-web