classification
Title: Expose a Process.sentinel property (and fix polling loop in Process.join())
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asksol, brian.curtin, gregory.p.smith, haypo, jnoller, neologix, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2011-05-09 18:39 by pitrou, last changed 2011-06-06 17:39 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
process_sentinel.patch pitrou, 2011-05-09 18:39 review
process_sentinel2.patch pitrou, 2011-05-12 16:18 review
Messages (6)
msg135623 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-05-09 18:39
This patch exposes a new read-only property of multiprocessing.Process objects, named "sentinel".
As the doc indicates, this is a file descriptor undex Unix, and a handle under Windows. Both are suitable for flexible polling/waiting with the appropriate OS primitives. They become ready when the process has ended.
Under Unix, this also replaces the repeated polling in _Popen.wait() (called from Process.join()) with a regular select() call, making it friendlier with CPU low-power states.

This is necessary for issue9205.
msg135844 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-05-12 16:18
Here is a new patch addressing Gregory's comment (retry select() on EINTR).
msg135929 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2011-05-13 17:08
That looks better. :)

btw, that eintr_retry utility probably deserves to be in a more
prominent place in the stdlib but I don't have a good suggestion as to
where at the moment.  I believe similar code exists in many places in
the code base.

If it is not going to be documented as an official
multiprocessing.util function, rename it to _eintr_retry().  that way
it'll be easier to move to a new place in the library if/when we do
want to make it public.
msg135930 - (view) Author: Charles-Fran├žois Natali (neologix) * (Python committer) Date: 2011-05-13 17:09
Just a detail, but with the last version, select is retried with the full timeout (note that the signal you're the most likely to receive is SIGCHLD and since it's ignored by default it won't cause EINTR, so this shouldn't happen too often).
By the way, it's not the first time EINTR-issues pop up: would it be possible/worth it/interesting to expose this kind of wrapper somewhere (even as a private API), or a context manager ?
msg136087 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-05-16 13:51
> Just a detail, but with the last version, select is retried with the
> full timeout (note that the signal you're the most likely to receive
> is SIGCHLD and since it's ignored by default it won't cause EINTR, so
> this shouldn't happen too often).

Indeed, it is. In practice we don't see anyone complaining about EINTR
issues, so I guess it's quite rare anyway.

> By the way, it's not the first time EINTR-issues pop up: would it be
> possible/worth it/interesting to expose this kind of wrapper somewhere
> (even as a private API), or a context manager ?

Yes, but where?
msg137758 - (view) Author: Roundup Robot (python-dev) Date: 2011-06-06 17:36
New changeset 568a3ba088e4 by Antoine Pitrou in branch 'default':
Issue #12040: Expose a new attribute `sentinel` on instances of
http://hg.python.org/cpython/rev/568a3ba088e4
History
Date User Action Args
2011-06-06 17:39:01pitrousetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2011-06-06 17:36:07python-devsetnosy: + python-dev
messages: + msg137758
2011-05-16 13:51:58pitrousetmessages: + msg136087
2011-05-13 17:09:57neologixsetmessages: + msg135930
2011-05-13 17:08:50gregory.p.smithsetmessages: + msg135929
2011-05-12 16:18:41pitrousetfiles: + process_sentinel2.patch

messages: + msg135844
2011-05-09 21:47:28hayposetnosy: + haypo
2011-05-09 18:40:42pitroulinkissue9205 dependencies
2011-05-09 18:39:21pitroucreate