Skip to content

bpo-39995: Fix race condition in ProcessPoolExecutor._ThreadWakeup #19751

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/concurrent/futures/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,30 @@ class _ThreadWakeup:
def __init__(self):
self._closed = False
self._reader, self._writer = mp.Pipe(duplex=False)
# Used to ensure pipe is not closed while sending or receiving bytes
self._not_running = threading.Event()
# Initialize event as True
self._not_running.set()

def close(self):
if not self._closed:
self._closed = True
self._not_running.wait()
self._writer.close()
self._reader.close()

def wakeup(self):
if not self._closed:
self._not_running.clear()
self._writer.send_bytes(b"")
self._not_running.set()

def clear(self):
if not self._closed:
self._not_running.clear()
while self._reader.poll():
self._reader.recv_bytes()
self._not_running.set()


def _python_exit():
Expand Down