简体   繁体   English

Python线程模块导入失败

[英]Python threading module import failure

I'm trying to import the threading module, however, i just seem to get errors for no good reason. 我正在尝试导入线程模块,但是,我似乎只是因为没有充分理由而得到错误。 Here is my code: 这是我的代码:

import threading

class TheThread ( threading.Thread ):
    def run ( self ):
        print 'Insert some thread stuff here.'
        print 'I\'ll be executed...yeah....'
        print 'There\'s not much to it.'

TheThread.Start()

And the errors: 而错误:

Traceback (most recent call last):
  File "threading.py", line 1, in <module>
    import threading
  File "C:\Users\Trent\Documents\Scripting\Python\Threading\threading.py", line
3, in <module>
    class TheThread ( threading.Thread ):
AttributeError: 'module' object has no attribute 'Thread'
Press any key to continue . . .

Python stats: Python统计数据:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win 32 获胜32的Python 2.7.2(默认,2011年6月12日,15:08:59)[MSC v.1500 32位(英特尔)]

i think that all you need is just to rename the name of your working file, because your file name is the same as module name: 我认为您只需重命名工作文件的名称,因为您的文件名与模块名称相同:

threading.py threading.py

or you have wrong threading.py file in your working directory 或者您的工作目录中有错误的threading.py文件

First, you have to rename your own file: It is called threading.py and since it is in the Python Path it replaces the threading module of the standard Python library. 首先,您必须重命名自己的文件:它被称为threading.py,因为它在Python Path中,它取代了标准Python库的线程模块。

Second, you have to create an instance of your thread-class: 其次,您必须创建线程类的实例:

TheThread().start() # start with latter case

_thread.start_new_thread(FUNC *)

我认为您使用了线程名称到您当前的工作文件。用不同的名称更改您的文件名。它会工作。它也适用于我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM