You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
multiprocessing.Process (actually, the _popen object attached to it) has a GC-based finalizer to release system resources (such as fds). However, it would be nice to be able to release those resources in a timely manner. Adding a close() method would let users do that. What do you think?
close() wouldn't terminate the underlying process, so the process would still exist (and wouldn't easily be stoppable from Python anymore) if you were to call close() before terminate() or join().
Perhaps we should instead mandate people call join() before close()?
jimjjewett commented on Jun 12, 2017
jimjjewettmannequin
Mannequin
More actions
Then why not just call join as part of the default close method?
That's a good question. close() methods on other objects tend to avoid taking an infinite amount of time :-) But then, Process objects are different enough that they don't need to follow that rule.
jimjjewett commented on Jun 12, 2017
jimjjewettmannequin
Mannequin
More actions
Could join be called in a background thread, or even asynchronously? That
seems like mixing paradigms, but ...
That's a good question. close() methods on other objects tend to avoid
taking an infinite amount of time :-) But then, Process objects are
different enough that they don't need to follow that rule.
I've decided it's better to raise a ValueError if the child process hasn't stopped yet. After all, join() alone may have no effect: often you want to send the process a signal (a literal signal in UNIX terms, or a figurative signal such as write something on a socket, etc.) to ask it to terminate gently.
Since the object now has a close() method, would it make sense to emit a ResourceWarning if it's not closed explicitly? As I did recently in subprocess.Popen destructor.
I don't think so. It is ok to let the GC delete the resources by itself. close() is just there for people who want to ensure whatever small amount of resources (a file descriptor, mostly) are released timely.
Activity
pitrou commentedon Jun 8, 2017
multiprocessing.Process (actually, the _popen object attached to it) has a GC-based finalizer to release system resources (such as fds). However, it would be nice to be able to release those resources in a timely manner. Adding a close() method would let users do that. What do you think?
pitrou commentedon Jun 8, 2017
close() wouldn't terminate the underlying process, so the process would still exist (and wouldn't easily be stoppable from Python anymore) if you were to call close() before terminate() or join().
Perhaps we should instead mandate people call join() before close()?
jimjjewett commentedon Jun 12, 2017
Then why not just call join as part of the default close method?
pitrou commentedon Jun 12, 2017
That's a good question. close() methods on other objects tend to avoid taking an infinite amount of time :-) But then, Process objects are different enough that they don't need to follow that rule.
jimjjewett commentedon Jun 12, 2017
Could join be called in a background thread, or even asynchronously? That
seems like mixing paradigms, but ...
On Jun 12, 2017 3:15 AM, "Antoine Pitrou" <report@bugs.python.org> wrote:
pitrou commentedon Jun 12, 2017
I want close() to be deterministic. So I guess we have two simple possibilities:
pitrou commentedon Jun 12, 2017
I've decided it's better to raise a ValueError if the child process hasn't stopped yet. After all, join() alone may have no effect: often you want to send the process a signal (a literal signal in UNIX terms, or a figurative signal such as write something on a socket, etc.) to ask it to terminate gently.
I'm gonna update the PR soon.
pitrou commentedon Jun 24, 2017
New changeset 13e96cc by Antoine Pitrou in branch 'master':
Fix bpo-30596: Add close() method to multiprocessing.Process (bpo-2010)
13e96cc
vstinner commentedon Jun 26, 2017
Since the object now has a close() method, would it make sense to emit a ResourceWarning if it's not closed explicitly? As I did recently in subprocess.Popen destructor.
pitrou commentedon Jun 26, 2017
I don't think so. It is ok to let the GC delete the resources by itself. close() is just there for people who want to ensure whatever small amount of resources (a file descriptor, mostly) are released timely.