mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
#1733757: the interpreter would hang on shutdown, if the function set by sys.settrace
calls threading.currentThread. The correction somewhat improves the code, but it was close. Many thanks to the "with" construct, which turns python code into C calls. I wonder if it is not better to sys.settrace(None) just after running the __main__ module and before finalization.
This commit is contained in:
parent
2aae1d92eb
commit
d7a265129c
3 changed files with 41 additions and 7 deletions
|
@ -238,6 +238,35 @@ class ThreadTests(unittest.TestCase):
|
|||
"""])
|
||||
self.assertEqual(rc, 42)
|
||||
|
||||
def test_finalize_with_trace(self):
|
||||
# Issue1733757
|
||||
# Avoid a deadlock when sys.settrace steps into threading._shutdown
|
||||
import subprocess
|
||||
rc = subprocess.call([sys.executable, "-c", """if 1:
|
||||
import sys, threading
|
||||
|
||||
# A deadlock-killer, to prevent the
|
||||
# testsuite to hang forever
|
||||
def killer():
|
||||
import os, time
|
||||
time.sleep(2)
|
||||
print 'program blocked; aborting'
|
||||
os._exit(2)
|
||||
t = threading.Thread(target=killer)
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
|
||||
# This is the trace function
|
||||
def func(frame, event, arg):
|
||||
threading.currentThread()
|
||||
return func
|
||||
|
||||
sys.settrace(func)
|
||||
"""])
|
||||
self.failIf(rc == 2, "interpreted was blocked")
|
||||
self.failUnless(rc == 0, "Unexpected error")
|
||||
|
||||
|
||||
def test_enumerate_after_join(self):
|
||||
# Try hard to trigger #1703448: a thread is still returned in
|
||||
# threading.enumerate() after it has been join()ed.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue