python - NameError:未定义名称“线程”将在终端中运行 Python 程序
问题描述
我在我的 python 文件中导入了以下模块:-
from socket import *
from threading import *
但是,我仍然收到此错误:-
NameError: name 'threading' is not defined
它在这一行显示错误:-
receive_thread = threading.Thread(target=receive)
谁能让我知道我该如何解决这个问题?任何帮助将不胜感激!谢谢:)
解决方案
如果您导入from threading import *
,则必须直接访问这些方法,而无需threading
先调用该类。因此,您只需从线程中导入每个方法并使用它们:
from threading import *
receive_thread = Thread(target=receive)
否则导入然后引用模块本身
import threading
receive_thread = threading.Thread(target=receive)
推荐阅读
- node.js - 异步从nodeJS中的sqlite数据库获取数据
- python - 在多线程环境中调试 python 多进程
- python - python balance bracket explanation
- javascript - 标记的 onClick 事件后,弹出窗口不会在 react-leaflet 中保持打开状态
- javascript - Vue CLI - 从本地 JSON 解析组件中的嵌套数据
- android - 如何从 Android Linux 内核获取当前工作目录?
- zapier - Zapier - 如何处理数组的所有条目?
- postgresql - 使用 current_date 获取过去 12 个月的月初和月底
- r - R:将列中每个值的前三个字符匹配到列表中,替换为列表中的值
- binary - 我们可以将 LSTM-RNN 应用于数值数据的二进制分类吗