Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-33997: Fix racing condition in termination of pool result_handler#8009

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
3mb3dw0rk5 wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
from3mb3dw0rk5:patch-2
Open
Changes from1 commit
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
NextNext commit
Fix racing condition in termination of pool result_handler
Fixes a racing condition when using Pool.terminate(). Sporadically the poll() function signals new data in the queue but get() never returns.This fix just consumes the two issued sentinels by the cleanup process.
  • Loading branch information
@3mb3dw0rk5
3mb3dw0rk5 authoredJun 29, 2018
commit984057c42ea5619c9f96cb52425bd545abe674e6
9 changes: 7 additions & 2 deletionsLib/multiprocessing/pool.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -464,6 +464,7 @@ def _handle_tasks(taskqueue, put, outqueue, pool, cache):
@staticmethod
def _handle_results(outqueue, get, cache):
thread = threading.current_thread()
sentinel_counter = 0

while 1:
try:
Expand All@@ -479,6 +480,7 @@ def _handle_results(outqueue, get, cache):

if task is None:
util.debug('result handler got sentinel')
sentinel_counter += 1
break

job, i, obj = task
Expand All@@ -497,6 +499,7 @@ def _handle_results(outqueue, get, cache):

if task is None:
util.debug('result handler ignoring extra sentinel')
sentinel_counter += 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This extra sentinel is no longer ignored, so the debug is wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Obviously right. Fixed that.

continue
job, i, obj = task
try:
Expand All@@ -511,10 +514,12 @@ def _handle_results(outqueue, get, cache):
# attempts to add the sentinel (None) to outqueue may
# block. There is guaranteed to be no more than 2 sentinels.
try:
for i in range(10):
while sentinel_counter < 2:
if not outqueue._reader.poll():
break
get()
task = get()
if task is None:
sentinel_counter += 1
except (OSError, EOFError):
pass

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp