This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients ita1024, martin.panter, python-dev, vstinner
Date 2017-01-06.10:09:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1483697349.86.0.917196654815.issue29174@psf.upfronthosting.co.za>
In-reply-to
Content
> 1. The call to warnings.warn is not usable during interpreter shutdown (and running `python -W ignore test.py` has no effect)

Oops right. I just fixed this issue.


> 2. Calling "process.terminate()" or "process.kill()" at in the testcase or in an atexit handler would not get rid of the warning, one must set the return code on the Popen object

Hum. I should document somehow how to fix such bug: you must read the exit status of the child process, not set manually the returncode attribute. You have to call the wait() method of each process after calling terminate().


> 3. The warning can show up in existing code that has absolutely no zombie problems.

I modified your example to list zombi processes: try test2.py.

Output:

$ ./python test2.py 
0  1000 25520 25120  20   0 140940 11828 wait   S+   pts/0      0:00 ./python test2.py
0  1000 25521 25520  20   0      0     0 -      Z+   pts/0      0:00 [python] <defunct>
0  1000 25522 25520  20   0      0     0 -      Z+   pts/0      0:00 [python] <defunct>
0  1000 25523 25520  20   0      0     0 -      Z+   pts/0      0:00 [python] <defunct>
0  1000 25524 25520  20   0      0     0 -      Z+   pts/0      0:00 [python] <defunct>
0  1000 25525 25520  20   0      0     0 -      Z+   pts/0      0:00 [python] <defunct>
0  1000 25526 25520  20   0      0     0 -      Z+   pts/0      0:00 [python] <defunct>
0  1000 25527 25520  20   0      0     0 -      Z+   pts/0      0:00 [python] <defunct>
0  1000 25528 25520  20   0      0     0 -      Z+   pts/0      0:00 [python] <defunct>
0  1000 25529 25520  20   0 119032  3008 wait   S+   pts/0      0:00 sh -c ps l|grep 25520
0  1000 25531 25529  20   0 118540   880 -      S+   pts/0      0:00 grep 25520
Lib/subprocess.py:761: ResourceWarning: subprocess 25528 is still running
sys:1: ResourceWarning: unclosed file <_io.FileIO name=18 mode='wb' closefd=True>
sys:1: ResourceWarning: unclosed file <_io.FileIO name=19 mode='rb' closefd=True>
(...)

The long list of <defunct> are the zombi processes: it means that the kernel is unable to remove completely child processes because the parent didn't read the exit status yet. Process identifiers and memory are wasted.

The warning can also help to detect when an application forgot to check the exit status. At least, if you add a call to process.wait(), it becomes explicit that ignoring the exit status is deliberate.
History
Date User Action Args
2017-01-06 10:09:09vstinnersetrecipients: + vstinner, python-dev, martin.panter, ita1024
2017-01-06 10:09:09vstinnersetmessageid: <1483697349.86.0.917196654815.issue29174@psf.upfronthosting.co.za>
2017-01-06 10:09:09vstinnerlinkissue29174 messages
2017-01-06 10:09:08vstinnercreate