我有一个应用程序,它使用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
EndsPython操作系统版本(& OS ):
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和Windows7上,上述代码似乎工作得很好。如果有人能帮我解决这个问题,我将不胜感激。
谢谢,
维诺德
发布于 2015-02-24 06:42:42
Tk和OS X有几个问题。https://www.python.org/download/mac/tcltk/
您应该考虑更新您的Tcl (或使用不同的实现)或Python。
https://stackoverflow.com/questions/28683913
复制相似问题