[issue9863] threading, signals, atexit: different execution with different versions
Corey Bertram
report at bugs.python.org
Wed Sep 15 21:02:22 CEST 2010
New submission from Corey Bertram <corey at qr7.com>:
my code works on python 2.6.2 and fails to work on python 2.6.5. What's going on here?
import atexit, sys, signal, time, threading
terminate = False
threads = []
def test_loop():
while True:
if terminate:
print('stopping thread')
break
else:
print('looping')
time.sleep(1)
@atexit.register
def shutdown():
global terminate
print('shutdown detected')
terminate = True
for thread in threads:
thread.join()
def close_handler(signum, frame):
print('caught signal')
sys.exit(0)
def run():
global threads
thread = threading.Thread(target=test_loop)
thread.start()
threads.append(thread)
while True:
time.sleep(2)
print('main')
signal.signal(signal.SIGINT, close_handler)
if __name__ == "__main__":
run()
python 2.6.2:
$ python halp.py
looping
looping
looping
main
looping
main
looping
looping
looping
main
looping
^Ccaught signal
shutdown detected
stopping thread
python 2.6.5:
$ python halp.py
looping
looping
looping
main
looping
looping
main
looping
looping
main
^Ccaught signal
looping
looping
looping
looping
...
looping
looping
Killed <- kill -9 process at this point
The main thread on 2.6.5 appears to never execute the atexit functions.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9863>
_______________________________________
More information about the Python-bugs-list
mailing list