This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: multiprocessing.Condition.notify_all() blocks indefinitely if a process waiting on it has died
Type: behavior Stage: needs patch
Components: Windows Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: davin, mickp, paul.moore, pitrou, sbt, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2017-07-20 11:29 by mickp, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
WaitersSleepers.py mickp, 2017-07-20 11:29 A script to demonstrate to the issue.
WaitersSleepers.py pitrou, 2017-07-20 14:05
Messages (4)
msg298713 - (view) Author: Mick Phillips (mickp) Date: 2017-07-20 11:29
If a process was waiting on an Event but dies for some reason, nothing else can set the Event. I think the Event._cond lock can not be acquired. See attached for a demonstration.

I see the same behaviour in Python 2.7.5 and Python 3.5.2. Is this expected behaviour?
msg298719 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-07-20 13:33
Hi Mick, thanks for reporting this issue.  You're right that the behaviour isn't expected.
msg298720 - (view) Author: Mick Phillips (mickp) Date: 2017-07-20 13:42
Thanks for confirming. If anyone finds this and is looking for a workaround, here's what I'm using:

while not event.is_set()
    try:
        time.sleep(timeout)
    except (KeyboardInterrupt, IOError):
        pass
msg298722 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-07-20 14:05
As a matter of fact, the bug is in Condition (which is used by Event.wait() but not by Event.is_set(), hence your workaround).  Here is a reproducer script.

This looks like a hard issue to solve.  There is no way to know whether a process that used to be waiting for a Condition was killed.
History
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75158
2017-07-20 14:20:00pitrousetnosy: + sbt
2017-07-20 14:05:30pitrousetfiles: + WaitersSleepers.py

messages: + msg298722
title: Multiprocessing: Event.set() blocks indefinitely if a process waiting on it has died. -> multiprocessing.Condition.notify_all() blocks indefinitely if a process waiting on it has died
2017-07-20 13:42:03mickpsetmessages: + msg298720
2017-07-20 13:33:16pitrousetversions: + Python 3.6, Python 3.7
nosy: + pitrou

messages: + msg298719

stage: needs patch
2017-07-20 11:29:48mickpcreate