【问题标题】:No "Thread" Module ( python 2.7 )没有“线程”模块(python 2.7)
【发布时间】:2018-02-05 16:12:57
【问题描述】:

由于某种原因,我在包含这段代码的行出现错误:

t1 = threading.Thread(target=socket)

这是错误:

Traceback (most recent call last):
  File "D:/04 - Media/Python Projects/4 - Networking/Send_Variable_Test/Server.py", line 33, in <module>
    t1 = threading.Thread(target=socket)
AttributeError: 'module' object has no attribute 'Thread'
Exception AttributeError: "'module' object has no attribute '_shutdown'" in <module 'threading' from 'D:\04 - Media\Python Projects\4 - Networking\Send_Variable_Test\threading.pyc'> ignored

从这个错误中可以明显看出线程库中显然没有“线程”模块,这是为什么呢?是我使用 python 2 的原因吗?

【问题讨论】:

    标签: python multithreading python-2.7


    【解决方案1】:

    您的路径中似乎有一个名为 threading.py 的文件。重命名它并删除 .pyc 文件,它应该可以工作。

    特别是在这个位置:D:\04 - Media\Python Projects\4 - Networking\Send_Variable_Test\threading.pyc

    【讨论】:

    • 我做到了,现在我不再收到错误了(而且 threading.py 是一件很愚蠢的事情)但现在我收到了这个错误:
    • '线程 Thread-1 中的异常:回溯(最后一次调用):文件“C:\Python27\lib\threading.py”,第 801 行,在 __bootstrap_inner self.run() 文件中“ C:\Python27\lib\threading.py", line 754, in run self.__target(*self.__args, **self.__kwargs) TypeError: 'module' object is not callable'
    • 等一下,发现问题
    • @HussamAl-hassan 由于原始问题已解决,我建议将答案标记为已接受,然后在出现任何新问题时打开一个新问题。您应该避免在 cmets 中提出全新的问题。特别是因为您提供的代码不允许进行太多调试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 1970-01-01
    相关资源
    最近更新 更多