我收到以下错误:
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'
我的代码如下所示:
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")
堆栈溢出抱怨,“看来您的帖子主要是代码;请添加更多详细信息。”因此,我将在这末尾添加一些文字;抱歉。
答案 0 :(得分:0)
如果收到此错误,则意味着您可能命名了一个自己的文件threading.py
。这样,导入将导入您自己的文件,而不是导入预期的库。
尽管这是一个愚蠢的错误,但希望有人在搜索“ AttributeError: module 'threading' has no attribute 'RLock'
”时会发现此答案会有所帮助。