Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用'threading'模块时出现问题--AttributeError:module';螺纹';没有属性';RLock&x27;_Python_Python 3.x_Multithreading - Fatal编程技术网

Python 使用'threading'模块时出现问题--AttributeError:module';螺纹';没有属性';RLock&x27;

Python 使用'threading'模块时出现问题--AttributeError:module';螺纹';没有属性';RLock&x27;,python,python-3.x,multithreading,Python,Python 3.x,Multithreading,我得到以下错误: AttributeError: module 'threading' has no attribute 'RLock' Exception ignored in: <module 'threading' from 'D:\\PYTHON_STACKOVERFLOW_ANSWERS\\threading.py'> AttributeError: module 'threading' has no attribute '_shutdown' Stack overflo

我得到以下错误:

AttributeError: module 'threading' has no attribute 'RLock'
Exception ignored in: <module 'threading' from 'D:\\PYTHON_STACKOVERFLOW_ANSWERS\\threading.py'>
AttributeError: module 'threading' has no attribute '_shutdown'

Stack overflow抱怨道,“看起来你的文章大部分都是代码,请添加更多细节。”所以我将把这一小段文字放在这里的末尾;对不起

如果出现此错误,则意味着您可能将自己的一个文件命名为
threading.py
,因此导入将导入您自己的文件,而不是导入预期的库

虽然这是一个愚蠢的错误,但希望有人通过谷歌搜索,“
AttributeError:module'threading'没有属性'RLock'
”会发现这个答案很有用

import logging
import threading
import time

def thread_function(name):
    logging.info("Thread %s: starting", name)
    time.sleep(2)
    logging.info("Thread %s: finishing", name)


if __name__ == "__main__":
    format = "%(asctime)s: %(message)s"
    logging.basicConfig(
        format=format,
        level=logging.INFO,
        datefmt="%H:%M:%S"
    )
    logging.info("Main    : before creating thread")
    x = threading.Thread(target=thread_function, args=(1,))
    logging.info("Main    : before running thread")
    x.start()
    logging.info("Main    : wait for the thread to finish")
    # x.join()
    logging.info("Main    : all done")