锁定代码块:
threadLock = threading.Lock()threadLock.acquire()# somecode...threadLock.release()
阻塞直到线程结束:
thread1 = myThread(1, "Thread-1", 1)thread2 = myThread(2, "Thread-2", 2)thread1.start()thread2.start() # 添加线程到线程列表threads.append(thread1)threads.append(thread2) # 等待所有线程完成for t in threads: t.join()print "Exiting Main Thread"
join([time])
方法: 等待至线程中止。
join()
方法被调用中止: - 正常退出
- 抛出未处理的异常
- 可选的超时发生。