Repository navigation
Python 3.10: Under some trivial circunstances, GIL not released #88811
Description
Activity
After #18334, a "while condition: pass" in a thread will preclude releasing the GIL, hanging the program with CPU at 100%.
Trivial to reproduce:
"""
#!/usr/bin/env python3.10import threading import time def worker(): while cont: pass def main(): global cont cont = True t = threading.Thread(target=worker) t.start() time.sleep(1) cont = False t.join() if __name__ == '__main__': main() """
- added3.10 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Jul 15, 2021 #18334 assumes that since all loops will contain a backwards edge, checking for interrupts on JUMP_ABSOLUTE should be sufficient.
However, #23743 changed the back edges in while statements. So
workercompiles to:2 0 LOAD_GLOBAL 0 (cont)
2 POP_JUMP_IF_FALSE 7 (to 14)3 >> 4 NOP
2 6 LOAD_GLOBAL 0 (cont)
8 POP_JUMP_IF_TRUE 2 (to 4)
10 LOAD_CONST 0 (None)
12 RETURN_VALUE
>> 14 LOAD_CONST 0 (None)
16 RETURN_VALUEwhich has no CALL or JUMP_ABSOLUTE instructions.
PR 27167 hangs or fails. in the refleak buildbots, so I am going to proceed to revert
To reproduce the problem:
$./python -m test test_threading -R : -v
...
test_original_excepthook (test.test_threading.ExceptHookTests) ... ok
test_system_exit (test.test_threading.ExceptHookTests) ... ok
test_can_interrupt_tight_loops (test.test_threading.InterruptMainTests) ...(HANGS here or some time fails like in:
======================================================================
FAIL: test_can_interrupt_tight_loops (test.test_threading.InterruptMainTests)
----------------------------------------------------------------------Traceback (most recent call last): File "/home/buildbot/buildarea/pull_request.cstratak-RHEL7-ppc64le.refleak/build/Lib/test/support/threading_helper.py", line 62, in decorator return func(*args) ^^^^^^^^^^^ File "/home/buildbot/buildarea/pull_request.cstratak-RHEL7-ppc64le.refleak/build/Lib/test/test_threading.py", line 1630, in test_can_interrupt_tight_loops self.assertNotEqual(iterations, 0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: 0 == 0
Can we at least include the fix, until we can come up with a better test?
That test fails on 3.9 as well as 3.10 and main.
With a 3.9 build and the test in bpo-27194:
./python -m test test_threading -R : 0:00:00 load avg: 0.95 Run tests sequentially 0:00:00 load avg: 0.95 [1/1] test_threading beginning 9 repetitions 123456789 ...test test_threading failed -- Traceback (most recent call last): File "/home/mark/repos/cpython/Lib/test/test_threading.py", line 1479, in test_can_interrupt_tight_loops self.assertNotEqual(iterations, 0) AssertionError: 0 == 0
I don't know what the underlying issue is.
Can you observe a failure without the -R flag?
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: