New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'NoneType' object is not callable in subprocess.py #73360
Comments
Please try the attached testcase with $ ../test.py
Exception ignored in: <bound method Popen.__del__ of <subprocess.Popen object at 0x7fe6744fc5c0>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/subprocess.py", line 761, in __del__
TypeError: 'NoneType' object is not callable
Exception ignored in: <bound method Popen.__del__ of <subprocess.Popen object at 0x7fe6744fc550>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/subprocess.py", line 761, in __del__ These warnings appear because of the line "warnings.warn" recently added in subprocess.Popen.del:
I suggest to revert the recently added warning from subprocess.py: """
@@ -754,11 +995,6 @@
if not self._child_created:
# We didn't get to successfully create a child process.
return
- if self.returncode is None:
- # Not reading subprocess exit status creates a zombi process which
- # is only destroyed at the parent python process exit
- warnings.warn("subprocess %s is still running" % self.pid,
- ResourceWarning, source=self)
# In case the child hasn't been waited on, check if it's done.
self._internal_poll(_deadstate=_maxsize)
if self.returncode is None and _active is not None:
""" |
New changeset b14a1e81c34a by Victor Stinner in branch '3.6': |
Oops right. I just fixed this issue.
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().
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. |
The point #3 was referring to the new requirement for an atexit handler in order to not only kill the processes but to also wait for them at interpreter shutdown. The sub-processes (and associated resources) in the example are definitely freed as the parent process is terminating. The recommended handler is not even always desirable (spawning daemon processes, key agents), it increases the code verbosity, impacts performance, and can even cause problems as child processes cannot always be waited on reliably (python 2 but also child -D state and platform-specific restrictions). I suggest to disable such warnings during interpreter shutdown. |
The ResourceWarning was added by bpo-26741. I agree that there are legitimate reasons why pre-3.6 code may avoid calling Popen.wait() and equivalent. Victor opened bpo-27068 about adding a Popen.detach() method, which such code could use to opt out of the warning. I don’t think there should be a special exemption for the warning at shutdown time. I think we should either:
|
Martin Panter:
I opened the issue because you asked me to open it, but I'm not
For this specific issue, the ResourceWarning is correct. I don't If your output is flooded by ResourceWarning warnings, it's easy to |
No, on this specific example the child processes do terminate properly as the parent process terminate. There is no extra resource consumption so the warning is incorrect and annoying.
At the moment the outputs are flooded with "exception ignored" messages that show how well this was thought out. Asking users to add -Wignore options for perfectly legitimate applications also shows how much consideration is being given to user experience, but we should not be surprised because that is how Python3 is being developed? Please remove this mess until a proper design is made and documented (3.7). |
The code in test.py is not realistic. It spawns children only to terminate them straight away, and you could easily reap each child after calling terminate(). You might have more influence with a realistic use case. Victor has committed a fix for the “exception ignored” problem, so assuming it works, in the next release of Python it should be gone. You should still see a ResourceWarning if warnings are enabled, but I don’t think -Wignore would be necessary to suppress them; such warnings are disabled by default. |
My application uses a process pool that gets freed when my application terminates.
I am reporting this because the users of my application are complaining.
I am looking forward to seeing that. Thanks Victor! |
This bug is now fixed if I understood correctly. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: