Re: [Python-Dev] subprocess shell=True on Windows doesn't escape ^ character
On 13/06/2014 03:11, Nikolaus Rath wrote:
> "R. David Murray" writes:
>> Also notice that using a list with shell=True is using the API
>> incorrectly. It wouldn't even work on Linux, so that torpedoes
>> the cross-platform concern already :)
>>
>> This kind of confusion is why I opened http://bugs.python.org/issue7839.
>
> Can someone describe an use case where shell=True actually makes sense
> at all?
On Windows (where I think the OP is), Popen & friends ultimately invoke
CreateProcess.
In the case where shell=True, subprocess invokes the command interpreter
explictly under the covers and tweaks a few other things to avoid a
Brief Flash of Unstyled Console. This is the relevant snippet from
subprocess.py:
if shell:
startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = _winapi.SW_HIDE
comspec = os.environ.get("COMSPEC", "cmd.exe")
args = '{} /c "{}"'.format (comspec, args)
That's all. It's more or less equivalent to your prefixing your commands
with "cmd.exe /c".
The only reasons you should need to do this are:
* If you're using one of the few commands which are actually built-in to
cmd.exe. I can't quickly find an online source for these, but typical
examples will be: "dir" or "copy".
* In some situations -- and I've never been able to nail this -- if
you're trying to run a .bat/.cmd file. I've certainly been able to run
batch files without shell=True but other people have failed within what
appears to be the same configuration unless invoking cmd.exe via
shell=True.
I use hg.exe (from TortoiseHg) but ISTR that the base Mercurial install
supplies a .bat/.cmd. If that's the OP's case then he might find it
necessary to pass shell=True.
TJG
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
[Python-Dev] Raspberry Pi Buildbot
Is there one? If not, would you like me to set one up? I've got one at home with Raspbian installed not doing anything, it could easily run a buildslave. Poking around on buildbot.python.org/all/builders, I can only see one ARM buildbot[1], and it's just called "ARM v7". I also found this python-dev thread[2] along with a blog.python.org blog post[3] from 2012, which mentioned that Trent Nelson would be receiving a Raspberry Pi and setting up a buildslave on it. But I can't find mention of it on buildbot.python.org. So I can't tell what the current state is. If anyone is interested, just let me know! .. [1]: http://buildbot.python.org/all/builders/ARMv7%203.x .. [2]: http://thread.gmane.org/gmane.comp.python.devel/136388 .. [3]: http://blog.python.org/2012/12/pandaboard-raspberry-pi-coming-to.html - Tal Einat ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] subprocess shell=True on Windows doesn't escape ^ character
On Fri, 13 Jun 2014 16:57:49 +1200, Greg Ewing wrote: > Nikolaus Rath wrote: > > you almost certainly want to do > > > > Popen(['/bin/sh', 'for i in `seq 42`; do echo $i; done'], shell=False) > > > > because if your shell happens to be tcsh or cmd.exe, things are going to > > break. > > On Unix, the C library's system() and popen() functions > always use /bin/sh, NOT the user's current login shell, > for this very reason. > > I would hope that the Python versions of these, and also > the new subprocess stuff, do the same. They do. > That still leaves differences between Unix and Windows, > but explicitly naming the shell won't help with that. There are some non-windows platforms where /bin/sh doesn't work (notably Android, where it is /system/bin/sh). See http://bugs.python.org/issue16353 for a proposal to create a standard way to figure out what the system shell should be for Popen's use. (The conclusion for Windows was to hardcode cmd.exe, though that isn't what the most recent patch there implements.) --David ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Moving Python 3.5 on Windows to a new compiler
On 06/10/2014 03:05 PM, "Martin v. Löwis" wrote: We certainly don't need to resolve this now. We should discuss it again when the release schedule for 3.5 is proposed. I anticipate 3.5 should be released about 18 months after the release of 3.4, putting it mid-September 2015. //arry/ ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] [Idle-dev] KeyConfig, KeyBinding and other related issues.
Hi, I would like the keyseq validator to be reviewed. The diff file: https://gist.github.com/sahutd/0a471db8138383fd73b2#file-test-keyseq-diff A sample test runner file: https://gist.github.com/sahutd/0a471db8138383fd73b2#file-test-keyseq-runner-py In its current form, it supports/has modifiers = ['Shift', 'Control', 'Alt', 'Meta'] alpha_uppercase = ['A'] alpha_lowercase = ['a'] direction = ['Up',] direction_key = ['Key-Up'] It supports validating combinations upto 4 in length. Please test for the above set only. (It will extended easily to fully represent the respective complete sets. The reason it cant be done *now* is the due to how RE optionals are coded differently in my patch. See CLEANUP below). I will also add remaining keys like Backspace, Slash etc tomorrow. # Cleanup: If we decide to go ahead with RE validating keys as in the above patch, 0. I made the mistake of not coding RE optionals -> ((pat)|(pat)) same for all sets. The result is that, extending the current key set is not possible without making all RE optional patterns similar.(Read the starting lines of is_valid_keyseq method). 1. There is a lot of places where refactoring can be done and appropriate comment added. 2. I left the asserts as-is. They can be used in testing the validator method itself. 3. The above patch still needs support for Backspace, slash etc to be added. I decided to add, once I am sure we will use it. 4. I would like to know how it will affect Mac? What are system specific differences? Please run the test-runner script on it and do let me know. --- My friend told that this thing can be done by "defining a grammar and automata." I did read up about it, but found it hard to grasp everything. Can you say whether it would be easier to solve it that way than RE? Regards On 13 June 2014 17:15, Saimadhav Heblikar wrote: > On 13 June 2014 16:58, Tal Einat wrote: >> On Fri, Jun 13, 2014 at 2:22 PM, Saimadhav Heblikar >> wrote: >>> Just a heads up to both: I am writing a keyseq validator method. >>> It currently works for over 800 permutations of ['Shift', 'Control', >>> 'Alt', 'Meta', 'Key-a', 'Key-A', 'Up', 'Key-Up', 'a', 'A']. It works >>> for permutations of length 2 and 3. Beyond that its not worth it IMO. >>> I am currently trying to integrate it with test_configuration.py and >>> catching permutations i missed out. >>> >>> I post this, so that we dont duplicate work. I hope it to be ready by >>> the end of the day.(UTC +5.5) >> >> What is the method you are using? > > Regex. It is not something elegant. The permutations are coded in.(Not > all 800+ obviously, but around 15-20 general ones.). The only > advantage is it can be used without creating a new Tk instance. > > >> >> What do you mean by "permutations"? If you mean what I think, then I'm >> not sure I agree with >3 not being worth it. I've used keyboard >> bindings with more than 2 modifiers before, and we should certainly >> support this properly. >> > I am sorry. I meant to write >3 modifier permutations. > (i.eControl-Shift-Alt-Meta+Key-X is not covered. But > Control-Shift-Alt-Key-X is.) > > > > > -- > Regards > Saimadhav Heblikar -- Regards Saimadhav Heblikar ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
[Python-Dev] python-dev for MAC OS X
Hey, does anybody know how to install the python-dev headers and libraries for MAC OS X? -- Pedro Issa Helou Network Communication Engineering + 36 20 262 9274 ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] python-dev for MAC OS X
On Fri, Jun 13, 2014 at 12:21 PM, Pedro Helou wrote: > Hey, > > does anybody know how to install the python-dev headers and libraries for > MAC OS X? Hi, This list is for discussing the development *of* Python, not *with* Python. Please ask on the python list, [email protected] (more info here[1]) or on the #python channel on the Freenode IRC server. StackOverflow is also a good place to search for information and ask questions. But while we're on the subject, on OSX I recommend using a binary package manager such as Homebrew[2] or Macports[3] for this. I have had good experiences using Homebrew. Good luck, - Tal Einat .. [1]: https://mail.python.org/mailman/listinfo/python-list .. [2]: http://brew.sh/ .. [3]: http://www.macports.org/ ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] [Idle-dev] KeyConfig, KeyBinding and other related issues.
Apologies for the accidental cross post. I intended to send it to idle-dev. I am sorry again :( On 13 June 2014 20:11, Saimadhav Heblikar wrote: > Hi, > > I would like the keyseq validator to be reviewed. > > The diff file: > https://gist.github.com/sahutd/0a471db8138383fd73b2#file-test-keyseq-diff > A sample test runner file: > https://gist.github.com/sahutd/0a471db8138383fd73b2#file-test-keyseq-runner-py > > In its current form, it supports/has > modifiers = ['Shift', 'Control', 'Alt', 'Meta'] > alpha_uppercase = ['A'] > alpha_lowercase = ['a'] > direction = ['Up',] > direction_key = ['Key-Up'] > > It supports validating combinations upto 4 in length. > > Please test for the above set only. (It will extended easily to fully > represent the respective complete sets. The reason it cant be done > *now* is the due to how RE optionals are coded differently in my > patch. See CLEANUP below). I will also add remaining keys like > Backspace, Slash etc tomorrow. > > # Cleanup: > If we decide to go ahead with RE validating keys as in the above patch, > > 0. I made the mistake of not coding RE optionals -> ((pat)|(pat)) same > for all sets. The result is that, extending the current key set is not > possible without making all RE optional patterns similar.(Read the > starting lines of is_valid_keyseq method). > > 1. There is a lot of places where refactoring can be done and > appropriate comment added. > > 2. I left the asserts as-is. They can be used in testing the validator > method itself. > > 3. The above patch still needs support for Backspace, slash etc to be > added. I decided to add, once I am sure we will use it. > > 4. I would like to know how it will affect Mac? What are system > specific differences? Please run the test-runner script on it and do > let me know. > > --- > My friend told that this thing can be done by "defining a grammar and > automata." I did read up about it, but found it hard to grasp > everything. Can you say whether it would be easier to solve it that > way than RE? > > Regards > > > > On 13 June 2014 17:15, Saimadhav Heblikar wrote: >> On 13 June 2014 16:58, Tal Einat wrote: >>> On Fri, Jun 13, 2014 at 2:22 PM, Saimadhav Heblikar >>> wrote: Just a heads up to both: I am writing a keyseq validator method. It currently works for over 800 permutations of ['Shift', 'Control', 'Alt', 'Meta', 'Key-a', 'Key-A', 'Up', 'Key-Up', 'a', 'A']. It works for permutations of length 2 and 3. Beyond that its not worth it IMO. I am currently trying to integrate it with test_configuration.py and catching permutations i missed out. I post this, so that we dont duplicate work. I hope it to be ready by the end of the day.(UTC +5.5) >>> >>> What is the method you are using? >> >> Regex. It is not something elegant. The permutations are coded in.(Not >> all 800+ obviously, but around 15-20 general ones.). The only >> advantage is it can be used without creating a new Tk instance. >> >> >>> >>> What do you mean by "permutations"? If you mean what I think, then I'm >>> not sure I agree with >3 not being worth it. I've used keyboard >>> bindings with more than 2 modifiers before, and we should certainly >>> support this properly. >>> >> I am sorry. I meant to write >3 modifier permutations. >> (i.eControl-Shift-Alt-Meta+Key-X is not covered. But >> Control-Shift-Alt-Key-X is.) >> >> >> >> >> -- >> Regards >> Saimadhav Heblikar > > > > -- > Regards > Saimadhav Heblikar -- Regards Saimadhav Heblikar ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
[Python-Dev] Summary of Python tracker Issues
ACTIVITY SUMMARY (2014-06-06 - 2014-06-13) Python tracker at http://bugs.python.org/ To view or respond to any of the issues listed below, click on the issue. Do NOT respond to this message. Issues counts and deltas: open4662 (+12) closed 28859 (+57) total 33521 (+69) Open issues with patches: 2150 Issues opened (52) == #15993: Windows: 3.3.0-rc2.msi: test_buffer fails http://bugs.python.org/issue15993 reopened by skrah #18910: IDle: test textView.py http://bugs.python.org/issue18910 reopened by ned.deily #20043: test_multiprocessing_main_handling fails --without-threads http://bugs.python.org/issue20043 reopened by berker.peksag #20578: BufferedIOBase.readinto1 is missing http://bugs.python.org/issue20578 reopened by benjamin.peterson #21684: inspect.signature bind doesn't include defaults or empty tuple http://bugs.python.org/issue21684 opened by rmccampbell7 #21686: IDLE - Test hyperparser http://bugs.python.org/issue21686 opened by sahutd #21687: Py_SetPath: Path components separated by colons http://bugs.python.org/issue21687 opened by fwalch #21690: re documentation: re.compile links to re.search / re.match ins http://bugs.python.org/issue21690 opened by jdg #21694: IDLE - Test ParenMatch http://bugs.python.org/issue21694 opened by sahutd #21696: Idle: test configuration files http://bugs.python.org/issue21696 opened by terry.reedy #21697: shutil.copytree() handles symbolic directory incorrectly http://bugs.python.org/issue21697 opened by shajunxing #21699: Windows Python 3.4.1 pyvenv doesn't work in directories with s http://bugs.python.org/issue21699 opened by Justin.Engel #21702: asyncio: remote_addr of create_datagram_endpoint() is not docu http://bugs.python.org/issue21702 opened by haypo #21703: IDLE: Test UndoDelegator http://bugs.python.org/issue21703 opened by sahutd #21704: _multiprocessing module builds incorrectly when POSIX semaphor http://bugs.python.org/issue21704 opened by Arfrever #21705: cgi.py: Multipart with more than one file is misparsed http://bugs.python.org/issue21705 opened by smurfix #21706: Add base for enumerations (Functional API) http://bugs.python.org/issue21706 opened by dkorchem #21707: modulefinder uses wrong CodeType signature in .replace_paths_i http://bugs.python.org/issue21707 opened by lemburg #21708: Deprecate nonstandard behavior of a dumbdbm database http://bugs.python.org/issue21708 opened by serhiy.storchaka #21710: --install-base option ignored? http://bugs.python.org/issue21710 opened by pitrou #21714: Path.with_name can construct invalid paths http://bugs.python.org/issue21714 opened by Antony.Lee #21715: Chaining exceptions at C level http://bugs.python.org/issue21715 opened by serhiy.storchaka #21716: 3.4.1 download page link for OpenPGP signatures has no sigs http://bugs.python.org/issue21716 opened by grossdm #21717: Exclusive mode for ZipFile and TarFile http://bugs.python.org/issue21717 opened by Antony.Lee #21718: sqlite3 cursor.description seems to rely on incomplete stateme http://bugs.python.org/issue21718 opened by zzzeek #21719: Returning Windows file attribute information via os.stat() http://bugs.python.org/issue21719 opened by benhoyt #21720: "TypeError: Item in ``from list'' not a string" message http://bugs.python.org/issue21720 opened by davidszotten #21721: socket.sendfile() should use TransmitFile on Windows http://bugs.python.org/issue21721 opened by giampaolo.rodola #21722: teach distutils "upload" to exit with code != 0 when error occ http://bugs.python.org/issue21722 opened by mdengler #21723: Float maxsize is treated as infinity in asyncio.Queue http://bugs.python.org/issue21723 opened by vajrasky #21724: resetwarnings doesn't reset warnings registry http://bugs.python.org/issue21724 opened by pitrou #21725: RFC 6531 (SMTPUTF8) support in smtpd http://bugs.python.org/issue21725 opened by r.david.murray #21726: Unnecessary line in documentation http://bugs.python.org/issue21726 opened by Reid.Price #21728: Confusing error message when initialising type inheriting obje http://bugs.python.org/issue21728 opened by Gerrit.Holl #21729: Use `with` statement in dbm.dumb http://bugs.python.org/issue21729 opened by Claudiu.Popa #21730: test_socket fails --without-threads http://bugs.python.org/issue21730 opened by berker.peksag #21731: Calendar Problem with Windows (XP) http://bugs.python.org/issue21731 opened by Juebo #21732: SubprocessTestsMixin.test_subprocess_terminate() hangs on "AMD http://bugs.python.org/issue21732 opened by haypo #21734: compilation of the _ctypes module fails on OpenIndiana: ffi_pr http://bugs.python.org/issue21734 opened by haypo #21735: test_threading.test_main_thread_after_fork_from_nonmain_thread http://bugs.python.org/issue21735 opened by haypo #21736: Add __file__ attribute to frozen modules http://bugs.python.org/issue21736 opened by lemburg #21737: runpy.run_path() fails with frozen __main
Re: [Python-Dev] subprocess shell=True on Windows doesn't escape ^ character
Florian Bruhin writes:
> * Nikolaus Rath [2014-06-12 19:11:07 -0700]:
>> "R. David Murray" writes:
>> > Also notice that using a list with shell=True is using the API
>> > incorrectly. It wouldn't even work on Linux, so that torpedoes
>> > the cross-platform concern already :)
>> >
>> > This kind of confusion is why I opened http://bugs.python.org/issue7839.
>>
>> Can someone describe an use case where shell=True actually makes sense
>> at all?
>>
>> It seems to me that whenever you need a shell, the argument's that you
>> pass to it will be shell specific. So instead of e.g.
>>
>> Popen('for i in `seq 42`; do echo $i; done', shell=True)
>>
>> you almost certainly want to do
>>
>> Popen(['/bin/sh', 'for i in `seq 42`; do echo $i; done'], shell=False)
>>
>> because if your shell happens to be tcsh or cmd.exe, things are going to
>> break.
>
> My usecase is a spawn-command in a GUI application, which the user can
> use to spawn an executable. I want the user to be able to use the
> usual shell features from there. However, I also pass an argument to
> that command, and that should be escaped.
You should pass the command as a string and use cmd.exe quote rules [1]
(note: they are different from the one provided by
`subprocess.list2cmdline()` [2] that follows Microsoft C/C++ startup
code rules [3] e.g., `^` is not special unlike in cmd.exe case).
[1]:
http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx
[2]:
https://docs.python.org/3.4/library/subprocess.html#converting-an-argument-sequence-to-a-string-on-windows
[3]: http://msdn.microsoft.com/en-us/library/17w5ykft%28v=vs.85%29.aspx
--
akira
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Backwards Incompatibility in logging module in 3.4?
On Thu, Jun 12, 2014 at 6:45 PM, Victor Stinner
wrote:
> Hi,
>
> 2014-06-13 0:38 GMT+02:00 Don Spaulding :
> > Is this a bug or an intentional break? If it's the latter, shouldn't
> this
> > at least be mentioned in the "What's new in Python 3.4" document?
>
> IMO the change is intentional. The previous behaviour was not really
> expected.
>
I agree that the change seems intentional. However, as Nick mentioned, the
ticket doesn't really discuss the repercussions of changing the output of
the function. As far as I can tell, this function has returned an int when
given a string since it was introduced in Python 2.3. I think it's
reasonable to call a function's behavior "expected" after 11 years in the
wild.
>
> Python 3.3 documentation is explicit: the result is a string and the
> input paramter is an integer. logging.getLevelName("DEBUG") was more
> an implementation
>
> https://docs.python.org/3.3/library/logging.html#logging.getLevelName
> "Returns the textual representation of logging level lvl. If the level
> is one of the predefined levels CRITICAL, ERROR, WARNING, INFO or
> DEBUG then you get the corresponding string. If you have associated
> levels with names using addLevelName() then the name you have
> associated with lvl is returned. If a numeric value corresponding to
> one of the defined levels is passed in, the corresponding string
> representation is returned. Otherwise, the string ‘Level %s’ % lvl is
> returned."
>
> If your code uses something like
> logger.setLevel(logging.getLevelName("DEBUG")), use directly
> logger.setLevel("DEBUG").
>
> This issue was fixed in OpenStack with this change:
> https://review.openstack.org/#/c/94028/6/openstack/common/log.py,cm
> https://review.openstack.org/#/c/94028/6
>
> Victor
>
I appreciate the pointer to the OpenStack fix. I've actually already
worked around the issue in my project (although without much elegance, I'll
readily admit).
I opened up an issue on the tracker for this:
http://bugs.python.org/issue21752
I apologize if that was out of turn.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] python-dev for MAC OS X
In article , Tal Einat wrote: > On Fri, Jun 13, 2014 at 12:21 PM, Pedro Helou wrote: > > does anybody know how to install the python-dev headers and libraries for > > MAC OS X? > This list is for discussing the development *of* Python, not *with* > Python. Please ask on the python list, [email protected] (more > info here[1]) or on the #python channel on the Freenode IRC server. > StackOverflow is also a good place to search for information and ask > questions. Like Tal said. But I'm guessing you are asking about the headers for the Apple-supplied System Pythons. On recent versions of OS X, they are not installed by default; you need to install the Command Line Tools component to install system headers include those for Python. How you do that varies by OS X release. In OS X 10.9 Mavericks, you can run "xcode-select --install". For earlier releases, there may be an option in Xcode.app's Preferences. Or you may be able to download the right Command Line Tools package from the Apple Developer Connection site. -- Ned Deily, [email protected] ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Backwards Incompatibility in logging module in 3.4?
On 14 Jun 2014 06:18, "Don Spaulding" wrote: > > I opened up an issue on the tracker for this: http://bugs.python.org/issue21752 > > I apologize if that was out of turn. At the very least, there should be a note in the "porting to Python 3.4" section of the What's New and a versionchanged note on the API docs, so a docs bug report is appropriate to add those. Cheers, Nick. > > ___ > Python-Dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com > ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Why does IOBase.__del__ call .close?
Benjamin Peterson writes:
> On Thu, Jun 12, 2014, at 18:06, Nikolaus Rath wrote:
>> Consider this simple example:
>>
>> $ cat test.py
>> import io
>> import warnings
>>
>> class StridedStream(io.IOBase):
>> def __init__(self, name, stride=2):
>> super().__init__()
>> self.fh = open(name, 'rb')
>> self.stride = stride
>>
>> def read(self, len_):
>> return self.fh.read(self.stride*len_)[::self.stride]
>>
>> def close(self):
>> self.fh.close()
>>
>> class FixedStridedStream(StridedStream):
>> def __del__(self):
>> # Prevent IOBase.__del__ frombeing called.
>> pass
>>
>> warnings.resetwarnings()
>> warnings.simplefilter('error')
>>
>> print('Creating & loosing StridedStream..')
>> r = StridedStream('/dev/zero')
>> del r
>>
>> print('Creating & loosing FixedStridedStream..')
>> r = FixedStridedStream('/dev/zero')
>> del r
>>
>> $ python3 test.py
>> Creating & loosing StridedStream..
>> Creating & loosing FixedStridedStream..
>> Exception ignored in: <_io.FileIO name='/dev/zero' mode='rb'>
>> ResourceWarning: unclosed file <_io.BufferedReader name='/dev/zero'>
>>
>> In the first case, the destructor inherited from IOBase actually
>> prevents the ResourceWarning from being emitted.
>
> Ah, I see. I don't see any good ways to fix it, though, besides setting
> some flag if close() is called from __del__.
How about not having IOBase.__del__ call self.close()? Any resources
acquired by the derived class would still clean up after themselves when
they are garbage collected.
Best,
-Nikolaus
--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
»Time flies like an arrow, fruit flies like a Banana.«
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Why does IOBase.__del__ call .close?
On Fri, Jun 13, 2014, at 20:04, Nikolaus Rath wrote:
> Benjamin Peterson writes:
> > On Thu, Jun 12, 2014, at 18:06, Nikolaus Rath wrote:
> >> Consider this simple example:
> >>
> >> $ cat test.py
> >> import io
> >> import warnings
> >>
> >> class StridedStream(io.IOBase):
> >> def __init__(self, name, stride=2):
> >> super().__init__()
> >> self.fh = open(name, 'rb')
> >> self.stride = stride
> >>
> >> def read(self, len_):
> >> return self.fh.read(self.stride*len_)[::self.stride]
> >>
> >> def close(self):
> >> self.fh.close()
> >>
> >> class FixedStridedStream(StridedStream):
> >> def __del__(self):
> >> # Prevent IOBase.__del__ frombeing called.
> >> pass
> >>
> >> warnings.resetwarnings()
> >> warnings.simplefilter('error')
> >>
> >> print('Creating & loosing StridedStream..')
> >> r = StridedStream('/dev/zero')
> >> del r
> >>
> >> print('Creating & loosing FixedStridedStream..')
> >> r = FixedStridedStream('/dev/zero')
> >> del r
> >>
> >> $ python3 test.py
> >> Creating & loosing StridedStream..
> >> Creating & loosing FixedStridedStream..
> >> Exception ignored in: <_io.FileIO name='/dev/zero' mode='rb'>
> >> ResourceWarning: unclosed file <_io.BufferedReader name='/dev/zero'>
> >>
> >> In the first case, the destructor inherited from IOBase actually
> >> prevents the ResourceWarning from being emitted.
> >
> > Ah, I see. I don't see any good ways to fix it, though, besides setting
> > some flag if close() is called from __del__.
>
> How about not having IOBase.__del__ call self.close()? Any resources
> acquired by the derived class would still clean up after themselves when
> they are garbage collected.
Well, yes, but that's probably a backwards compat problem.
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Raspberry Pi Buildbot
On Fri, Jun 13, 2014 at 3:24 AM, Tal Einat wrote: > Is there one? If not, would you like me to set one up? I've got one at > home with Raspbian installed not doing anything, it could easily run a > buildslave. > > Poking around on buildbot.python.org/all/builders, I can only see one > ARM buildbot[1], and it's just called "ARM v7". > The ARM v7 buildbot is mine. It's a Samsung chromebook with a dual core exynos5 cpu and usb3 SSD. ie: It's *at least* 10x faster than a raspberry pi. I don't think a pi buildbot would add much value but if you want to run one, feel free. It should live in the unstable pool. -gps ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
