#!/usr/bin/python import thread, threading, time, sys def print_ (): sys.stdout.flush() for i in range(10): time.sleep(1) print "mythread: ticking ", i sys.stdout.flush() raise NotImplementedError if len(sys.argv) < 2: print "Running old thread module test" thread.start_new_thread(print_,()) time.sleep(1) thread.start_new_thread(print_,()) time.sleep(1) thread.start_new_thread(print_,()) elif len(sys.argv) == 2: print "Running threading module test" threading.Thread(target=print_).start() time.sleep(1) threading.Thread(target=print_).start() time.sleep(1) threading.Thread(target=print_).start() else: print "Running threading module test - threads are daemons" t1 = threading.Thread(target=print_) t1.setDaemon(True) t1.start() time.sleep(1) t2 = threading.Thread(target=print_) t2.setDaemon(True) t2.start() time.sleep(1) t3 = threading.Thread(target=print_) t3.setDaemon(True) t3.start() time.sleep(1)