Issue 9814: subprocess isn't friendly to other Python implementations with different GCs (original) (raw)

Issue9814

Created on 2010-09-09 22:58 by dino.viehland, last changed 2022-04-11 14:57 by admin.

Messages (2)
msg115979 - (view) Author: Dino Viehland (dino.viehland) * (Python committer) Date: 2010-09-09 22:58
subprocess isn't very friendly to implementations with different GCs then CPython and in general relies on behavior that's not going to be very stable. I noticed the following issues but was able to work around all of them. First Popen is a finalizable object which holds onto another finalizable object (the process handle). In __del__ Popen calls internal poll which attempts to wait on the handle. But because both the handle and the POpen object can go out of scope at the same time the handle can be finalized first. The end result is that you cannot get the return code and therefore the Popen class will resurrect it's self. That will at the very least leak the Popen object and when running the subprocess tests will eventually start failing all of the tests. For me this was happening because test_cwd doesn't call wait and therefore never explicitly gets the exit code. Resurrecting finalizable objects seems like a pretty bad idea and seems to be there only for test purposes - after all who cares if you collect the exit code after no one refers to the object. Unless _active is supposed to be publicly exposed? Another issue is relying on CPython's reference counting garbage collcetion. In particular _get_handles on Windows does "p2cread = self._make_inheritable(p2cread)" where stdin == PIPE. On CPython this is going to remove the 1 reference to the previous p2cread and close it immediately. With other GCs this reference will linger around only to be closed at some point. Usually that's not a problem but because this handle remains in the parent process the pipe does not get closed when it should resulting in hangs. This is effectively a duplicated handle of the handle _execute_child closes after the child is launched.
msg116131 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-09-11 23:18
I think all developers agree that we should play nice with all VMs. Do you want to make patches for these problems?
History
Date User Action Args
2022-04-11 14:57:06 admin set github: 54023
2013-07-08 14:38:51 christian.heimes set versions: + Python 3.3, Python 3.4, - Python 3.1, Python 3.2
2010-09-11 23🔞29 eric.araujo set versions: + Python 3.1, Python 2.7, Python 3.2nosy: + eric.araujo, astrandmessages: + stage: needs patch
2010-09-09 22:58:32 dino.viehland create