Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在构建一个与 py2app 一起分发的应用程序。因为我不希望从 .app 文件中提取源代码,所以我有一个名为 run.py 的存根文件,然后运行 mainapp.py 中的代码:
import mainapp
直接在终端中运行(不涉及 py2app)会冻结与 gevent 相关的代码部分。变成.app时的结果是一样的。以上述方式导入是否会改变解释器的任何环境?似乎很奇怪,只是冻结,没有错误消息(没有 try/catch 块。)
在 Python 中导入模块时,会执行该模块。确保mainapp没有“免费代码”可以冻结您的 python VM(如无限循环)。
mainapp
“自由代码”是函数或类定义之外的指令集。
例如在
import one_module while(true) : various_code() def foo() : print "bar"
第二行是自由代码。
当我尝试导入此脚本时,将while执行指令并冻结 python。
while