多线程和多处理是否有或不用此操作:
多线程和多处理的工作,或者有或没有此功能, 如果__NAME __ ==“ __ Main __”
??
Will Multithreading and Multiprocessing work with or without this,if __name__=="__main__"
??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
__名称__
是一个全局变量,自动初始化以引用字符串 - 模块 其中__ name __ name __
出现或特殊值,“ __ main __”
,如果出现在脚本或顶级程序中。此模式在许多python源文件中使用:
如果将源文件作为脚本运行,则运行测试/演示代码,或者如果源文件为
导入
导入
multiprocessing
://docs.python.org/3/library/threading.html“ rel =“ nofollow noreferrer”>
螺纹>螺纹>
不会更改if nbsp; __名称 “ __ main __”
做,并且if;代码>做。这些模块与任何其他python模块没有什么不同(例如,
MATH
或
或time
sys
)__name__
is a global variable that is automatically initialized to refer to a string—either the name of the module in which__name__
appears or, the special value,"__main__"
, if it appears in a script or top-level program.This pattern is used in many Python source files:
The test/demo code is run if you run the source file as a script, or it doesn't get run if the source file is
import
ed as a module.Importing
multiprocessing
orthreading
doesn't change whatif __name__ == "__main__"
does, andif __name__ == "__main__"
doesn't change whatmultiprocessing
orthreading
do. Those modules are no different in that respect from any other Python module (e.g.,math
, ortime
, orsys
)