Skip to content

Commit 995a14c

Browse files
committed
fixup! gh-105829: Add test to demonstrate deadlock
Try to reduce the size of the pipe to make the test faster. The solution only works on Unix-like platforms, we fall back on a hardcoded size for other platforms.
1 parent 47a6b75 commit 995a14c

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Lib/test/test_concurrent_futures.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,16 +1412,29 @@ def mock_run(self):
14121412
time.sleep(5)
14131413
thread_run(self)
14141414

1415-
# Should be support.PIPE_MAX_SIZE but it is way too
1416-
# pessimistic here, would take too long. Assume 64k pipe
1417-
# buffer and add some margin...
1418-
job_num = 65536 * 2
1419-
job_data = range(job_num)
1415+
def adjust_and_check_jobs_needed_to_block_pipe(connection):
1416+
try:
1417+
# Try to reduce pipe size to speed up test. Only works on Unix systems
1418+
import fcntl
1419+
from fcntl import F_SETPIPE_SZ
1420+
pipe_size = fcntl.fcntl(connection.fileno(), F_SETPIPE_SZ, 1024)
1421+
except ImportError:
1422+
# Assume 64k pipe if we fail, makes test take longer
1423+
pipe_size = 65536
1424+
1425+
# We send 4 bytes per job (one zero sized bytes object)
1426+
return pipe_size // 4 + 100 # Add some margin
1427+
14201428
with unittest.mock.patch.object(futures.process._ExecutorManagerThread, 'run', mock_run):
14211429
with self.executor_type(max_workers=2,
14221430
mp_context=self.get_context()) as executor:
14231431
self.executor = executor # Allow clean up in fail_on_deadlock
14241432

1433+
# Try to speed up the test by reducing the size of the wakeup pipe
1434+
job_num = adjust_and_check_jobs_needed_to_block_pipe(
1435+
executor._executor_manager_thread_wakeup._writer)
1436+
job_data = range(job_num)
1437+
14251438
# Need to use sigalarm for timeout detection because
14261439
# Executor.submit is not guarded by any timeout (both
14271440
# self._work_ids.put(self._queue_count) and

0 commit comments

Comments
 (0)