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
multiprocessing sentinel resource leak #70919
Comments
The sentinel creates a named pipe, but the parent's end of the pipe is inherited by subsequently created children. import multiprocessing,signal,sys
def sproc(x): signal.pause()
for each in range(int(sys.argv[1])):
multiprocessing.Process(target=sproc, args=(each,)).start()
signal.pause() Running the above on Linux with varying numbers of child processes (expressed as the argument to the above) and using techniques like "$ sudo ls /proc/NNNN/fd" it is possible to see an ever growing number of pipe connections for subsequent children. |
(Sorry, an unnamed pipe, but a pipe nonetheless.) |
I confirm the issue with Python 3.6 on Linux. File descriptors of the parent process: haypo@selma$ ls -l /proc/31564/fd/ File descriptors of the first child process: haypo@selma$ ls -l /proc/31565/fd/ File descriptors of the second child process: haypo@selma$ ls -l /proc/31566/fd/ (...) File descriptors of the last child process: haypo@selma$ ls -l /proc/31574/fd/ |
This is expected with the "fork" method, but also happens with the "forkserver" method. |
The newly added test now hangs on almost all Windows buildbots, see: |
By the way, 3.6 is marked as affected, but the change wasn't backported to 3.6? |
Thank you for the fix, pitrou! Regarding your comment regarding the behavior being expected with the "fork" method, I would suggest a documentation modification in the description of the fork method to add something to the effect of "All resources of the parent are inherited by the child process; this includes the ability of later children to act as the parent of earlier children via the various functions in this package." |
Victor, you can try to backport the fix, it should be interesting, though I suspect you will run into conflicts :-) |
Kevin:
I would rather keep the latter part ("the ability of later children to act as the parent of earlier children via the various functions in this package") an implementation detail rather than a documented feature. Who knows, perhaps some day we'll change the implementation so that those are not inherited anymore. |
IIRC sockets can be marked as inheritable or not. It seems to me it would be a useful enhancement to allow the same determination for the pipes. |
Hi Antoine,
I understand your desire, but this is a leaky abstraction and I would still suggest that it should be more clear that the fork method will inherit *all* resources from the parent, including multiprocessing internal resources related to other processes. This is potentially important if there are (a) large numbers of processes to be created and (b) for security aspects. Regards, |
Backport to 3.6 is no longer relevant. Is there anything left to do here? |
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: