classification
Title: multiprocessing.Condition.wait_for missing
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: neologix, pitrou, python-dev, sbt
Priority: normal Keywords: patch

Created on 2012-02-22 15:01 by sbt, last changed 2012-04-17 17:30 by neologix. This issue is now closed.

Files
File name Uploaded Description Edit
cond_wait_for.patch sbt, 2012-02-23 13:41
cond_wait_for.patch sbt, 2012-02-24 13:26
cond_wait_for.patch sbt, 2012-04-07 22:36 review
cond_wait_for.patch sbt, 2012-04-16 14:42 review
Messages (11)
msg153956 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-02-22 15:01
multiprocessing.Condition is missing a counterpart for the wait_for() method added to threading.Condition in Python 3.2.

I will work on a patch.
msg154063 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-02-23 13:41
Patch which just copies the implementation from threading.
msg154093 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2012-02-23 22:06
In test/test_multiprocessing.py:
"""
   def test_waitfor(self):
       [...]
       with cond:
           result = cond.wait_for(lambda : state.value==0)
           self.assertTrue(result)
           self.assertEqual(state.value, 0)
           for i in range(4):
               time.sleep(0.01)
               with cond:
                   state.value += 1
                   cond.notify()
"""

Shouldn't the `for` loop be outside the outer `with` block?

In Lib/multiprocessing/managers.py:
Is there a good reason why the wait_for() proxy method can't simply be implemented as:
return self._callmethod('wait_for', (predicate, timeout))?

(There may be, I just didn't check).

Finally, the documentation should be updated (Doc/library/multiprocessing.rst).

Otherwise, it would probably be better if you could submit a contributor agreement (and also maybe update your name on the tracker), unless that's a problem for you?
msg154135 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-02-24 13:26
> Shouldn't the `for` loop be outside the outer `with` block?

Yes.

> In Lib/multiprocessing/managers.py:
> Is there a good reason why the wait_for() proxy method can't simply be
> implemented as:
> return self._callmethod('wait_for', (predicate, timeout))?
> 
> (There may be, I just didn't check).

That would only work if predicate is picklable, which is unlikely to be the case.  (The lambda functions used in the unit tests are not picklable.)

> Finally, the documentation should be updated 
> (Doc/library/multiprocessing.rst).

Fixed in new patch.

> Otherwise, it would probably be better if you could submit a contributor 
> agreement (and also maybe update your name on the tracker), unless that's
> a problem for you?

I will try to submit it over the weekend.
msg157244 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-03-31 23:54
AFAICT (Raw)Value relies on ctypes, so the tests should be skipped if ctypes is unavailable. Or I guess you could use a Semaphore instead.
msg157762 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-04-07 22:36
New patch skips tests if ctypes not available.
msg158459 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-04-16 14:42
New patch which calculates endtime outside loop.
msg158497 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-04-16 20:16
Charles-François, will you take this one? :)
msg158533 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2012-04-17 07:32
> Charles-François, will you take this one? :)

Yes :-)
msg158557 - (view) Author: Roundup Robot (python-dev) Date: 2012-04-17 16:46
New changeset 5606ee052783 by Charles-François Natali in branch 'default':
Issue #14087: multiprocessing: add Condition.wait_for(). Patch by sbt.
http://hg.python.org/cpython/rev/5606ee052783
msg158559 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2012-04-17 17:30
Committed.
Thanks for the patch, and sorry for the delay!
History
Date User Action Args
2012-04-17 17:30:15neologixsetstatus: open -> closed
resolution: fixed
messages: + msg158559

stage: commit review -> resolved
2012-04-17 16:46:49python-devsetnosy: + python-dev
messages: + msg158557
2012-04-17 07:32:52neologixsetmessages: + msg158533
2012-04-16 20:16:30pitrousetmessages: + msg158497
2012-04-16 14:42:52sbtsetfiles: + cond_wait_for.patch

messages: + msg158459
2012-04-07 22:36:42sbtsetfiles: + cond_wait_for.patch

messages: + msg157762
2012-03-31 23:54:06pitrousetmessages: + msg157244
2012-03-31 23:42:54pitroulinkissue14059 dependencies
2012-03-26 14:53:33neologixsetnosy: + pitrou

stage: commit review
2012-02-24 13:26:56sbtsetfiles: + cond_wait_for.patch

messages: + msg154135
2012-02-23 22:06:20neologixsetnosy: + neologix
messages: + msg154093
2012-02-23 13:41:23sbtsetfiles: + cond_wait_for.patch
keywords: + patch
messages: + msg154063
2012-02-22 15:01:24sbtcreate