【发布时间】:2015-02-24 06:42:41
【问题描述】:
我有一个使用 tkMessageBox 模块、多处理模块和 urllib2 模块的应用程序。由于某些未知原因,python 子进程在获取 url 时会静默崩溃。这仅在导入 tkMessageBox 模块时发生。
这是我重现问题的示例代码:
import tkMessageBox
import multiprocessing
import time
import urllib2
def run():
print "Starts"
urllib2.urlopen("http://stackoverflow.com").read()
print "Ends"
def start_process():
p = multiprocessing.Process(target=run)
p.start()
def main():
start_process()
while True:
time.sleep(1)
if __name__ == "__main__":
main()
输出:
python test_tk.py
Starts
如果我注释了 tkMessageBox 导入行,程序运行成功。
输出:
python test_tk.py
Starts
Ends
Python 和操作系统版本:
python
ActivePython 2.7.8.10 (ActiveState Software Inc.) based on
Python 2.7.8 (default, Jul 7 2014, 20:30:57)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
>>> Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
platform.mac_ver()
('10.10.2', ('', '', ''), 'x86_64')
我不知道这里发生了什么。我已经在 MacOSX 10.10.2 上对其进行了测试,它是可重现的。但在 Ubuntu 14.04 和 Windows 7 上,上面的代码似乎运行良好。如果有人可以帮助我解决这个问题,我将不胜感激。
谢谢,
维诺德
【问题讨论】:
标签: python macos tkinter multiprocessing urllib2