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
multiprocessing.Queue.join_thread() does nothing if created and use in the same process #75069
Comments
test_handle_called_with_mp_queue (test.test_logging.QueueListenerTest) ... Warning -- threading_cleanup() failed to cleanup -1 threads after 3 sec (count: 0, dangling: 1) |
The load average was 3.15: 0:04:33 load avg: 3.15 [176/406] test_logging failed (env changed) -- Another fail on AMD64 FreeBSD CURRENT Non-Debug 3.x: 0:01:56 load avg: 3.45 [ 44/406] test_logging failed (env changed) |
Previous issue which fixed QueueListenerTest of test_logging is bpo-30131: commit 8ca2f2f
|
While trying to reproduce the bug, I got: test_handle_called_with_mp_queue (test.test_logging.QueueListenerTest) ... /usr/home/haypo/cpython/Lib/test/support/init.py:1515: ResourceWarning: unclosed <socket.socket fd=6, family=AddressFamily.AF_INET, type=536870913, proto=0, laddr=('127.0.0.1', 8166), raddr=('127.0.0.1', 8167)> |
The problem is that multiprocessing.Queue.join_thread() does nothing since the thread wasn't started by a subprocess. See also bpo-30171: Emit ResourceWarning in multiprocessing Queue destructor. |
The warning is a race condition which can be reproduced easily on Linux using attached test_handle_called_with_mp_queue-bug.patch, run: haypo@selma$ ./python -m test --fail-env-changed -m test_handle_called_with_mp_queue test_logging 1 test altered the execution environment: Total duration: 718 ms |
#2642 fixes the warning. I tested the change with test_handle_called_with_mp_queue-bug.patch: no more warning. Sorry, I don't know multiprocessing to understand the purpose of the removed test. I would like to really make sure that a Queue object doesn't "leak" a thread when I close .close() + .join_thread(). It's surprising that .join_thread() doesn't join anything and leave a thread running in the background. Even if in the common case, when the system load is low, the thread quits quickly thanks to .close(). |
Hum, interesting, created_by_this_process was already removed from Python 2.7 in bpo-4106: commit 77657e4
|
I don't understand how this happens. The Finalize object only acts as an atexit handler. When called as a regular finalize, |
Oh, that's because you're calling join_thread() explicitly. I see. I agree that the fix looks desirable then. |
If you run "./python -m test --fail-env-changed -m test_handle_called_with_mp_queue test_logging" with attached test_handle_called_with_mp_queue-bug.patch, no finalizer is registered: .join_thread() does nothing, because created_by_this_process is true. |
FYI I added join_thread() in my first attempt to fix "Warning -- threading._dangling was modified by test_logging": bpo-30131, commit 8ca2f2f. I expected that join_thread() would... join the thread :-) |
I suggest to backport the fix up to Python 3.5. |
Ok, I applied my fix to 3.5, 3.6 and master branches. Thanks for the review Antoine. |
I'm not sure that the bug is fully fixed, I still saw a warning on: This build tested the commit aa8d0a2 which is more recent than commit 3b69d91. test_handle_called_with_mp_queue (test.test_logging.QueueListenerTest) ... Warning -- threading_cleanup() failed to cleanup -1 threads after 5 sec (count: 0, dangling: 1) ok |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: