我有 3 个线程,它们当前同时运行。
def f1():
print "running first thread\n"
sleep(10)
def f2():
print "running second thread\n"
sleep(10)
def f3():
print "running third thread\n"
sleep(10)
if __name__ == "__main__":
thread1 = Thread(target = f1)
thread2 = Thread(target = f2)
thread3 = Thread(target = f3)
try:
thread1 = Thread(target = f1)
thread1.start()
thread2 = Thread(target = f2)
thread2.start()
thread3 = Thread(target = f3)
thread3.start()
while(thread1.isAlive() or thread2.isAlive() or thread3.isAlive()):
thread1.join()
thread2.join()
thread3.join()
except (KeyboardInterrupt, SystemExit):
sys.exit()
如何模拟死锁?另外,我怎样才能让每个线程一个接一个地运行?我还可以列出当前在我的脚本中运行的所有线程吗?还是给他们优先权?