使用Timer进行Python线程处理

时间:2010-07-19 15:29:08

标签: python multithreading timer

我希望Python中的3个Threads运行n秒。我想同时启动它们并让它们同时完成(在几毫秒内)。我该怎么做?

threading.Timer仅在前一个完成后开始。

1 个答案:

答案 0 :(得分:4)

import threading 
import time

class A(threading.Thread):
  def run(self):
     print "here", time.time()
     time.sleep(10)
     print "there", time.time()


if __name__=="__main__":
  for i in range(3):
     a = A()
     a.start()

打印:

here 1279553593.49
here 1279553593.49
here 1279553593.49
there 1279553603.5
there 1279553603.5
there 1279553603.5