Python线程错误,无法运行脚本

时间:2018-01-06 04:27:59

标签: python multithreading

我不知道为什么,但是当我尝试运行我的一个python程序时,我一直收到错误。这是一个简单的脚本,因为我试图理解线程是如何工作的。

这是我用于示例的代码:

import threading
import time

def myfunction():
    print("Start a thread")
    time.sleep(3)
    print ("End a thread")

threads = []

for i in range(5):
    #thread object
    thread = threading.Thread(target=myfunction)
    thread.start
    threads.append(thread)




for thread in threads:
    thread.join()

这是我在执行脚本时收到的错误:

Traceback (most recent call last):
  File "blue.py", line 13, in <module>
    thread = threading.Thread(target=myfunction)
AttributeError: 'module' object has no attribute 'Thread'
Exception AttributeError: "'module' object has no attribute '_shutdown'" in <module 'threading' from '/home/user/Desktop/threading.pyc'> ignore

感谢所有回复的人!

编辑:所以我现在遇到了一个不同的错误,如下所示:

Traceback (most recent call last):
  File "blue.py", line 21, in <module>
    thread.join()
  File "/usr/lib/python2.7/threading.py", line 929, in join
    raise RuntimeError("cannot join thread before it is started")
RuntimeError: cannot join thread before it is started

0 个答案:

没有答案