This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cbertram
Recipients cbertram
Date 2010-09-15.19:02:19
SpamBayes Score 2.3653351e-06
Marked as misclassified No
Message-id <1284577342.31.0.557156421767.issue9863@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-09-15 19:02:22cbertramsetrecipients: + cbertram
2010-09-15 19:02:22cbertramsetmessageid: <1284577342.31.0.557156421767.issue9863@psf.upfronthosting.co.za>
2010-09-15 19:02:20cbertramlinkissue9863 messages
2010-09-15 19:02:19cbertramcreate