小编Utk*_*tel的帖子

线程未在 python 脚本中并行运行

我是 python 和线程的新手。我试图一次运行多个线程。这是我的基本代码:

  import threading
  import time
  threads = []

  print "hello"

  class myThread(threading.Thread):
          def __init__(self,i):
                  threading.Thread.__init__(self)
                  print "i = ",i
                  for j in range(0,i):
                          print "j = ",j
                          time.sleep(5)

  for i in range(1,4):
          thread = myThread(i)
          thread.start()
Run Code Online (Sandbox Code Playgroud)

当 1 个线程正在等待时,time.sleep(5)我希望启动另一个线程。简而言之,所有线程都应该并行运行。

python multithreading python-2.7

2
推荐指数
1
解决办法
7994
查看次数

标签 统计

multithreading ×1

python ×1

python-2.7 ×1