New submission from Steve: I am attempting to join a thread after a previous join was interrupted by Ctrl-C.
I did not find any warning for this case in threading module docs, so I assume this is legal. The full test script is attached, but the essential code is: def work(t): sleep(t) twork = 3; twait = 4 t = Thread(target=work, args=(twork,)) try: t.start() t.join(twait) # here I do Ctrl-C except KeyboardInterrupt: pass t.join() # this hangs if twork < twait I can observe the following reproduce sequence: 1. start another thread that sleeps (or works) for T seconds 2. join that thread with timeout longer than T 3. before thread finishes and join returns, hit Ctrl-C to raise KeyboardInterrupt (KI) 4. after T seconds, thread finishes its (Python) code and KI is raised 5. Process Explorer confirms that thread really terminates (looked at .ident()) 6. thread still reports .is_alive() == True 7. second attempt to join that thread hangs indefinitely I tried replacing try-except clause with custom signal handler for SIGINT, as shown in the script. If the handler does not raise an exception, the thread can be normally joined. If it does, however, the behavior is the same as with default handler. My _guess_ is that the exception prevents some finishing code that puts Thread into proper stopped state after its target completes. Running Python 3.4.0 on Windows 7 x64 ---------- components: Library (Lib) files: join.py messages: 221180 nosy: tupl priority: normal severity: normal status: open title: KeyboardInterrupt during Thread.join hangs that Thread versions: Python 3.4 Added file: http://bugs.python.org/file35715/join.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21822> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com