import thread from time import sleep def f(i, lock): try: sleep(10) except KeyboardInterrupt: print "%d interrupted" % i else: print "%d timed out" % i lock.release() N = 10 locks = [thread.allocate_lock() for i in range(N)] for lock in locks: lock.acquire() for i in range(N): thread.start_new_thread(f, (i, locks[i])) for lock in locks: lock.acquire()