导入tkMessageBox时,运行urlopen的MacOSX Python子进程崩溃



我有一个应用程序,它使用tkMessageBox模块、多处理模块和urlib2模块。由于某种未知的原因,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和Windows7上,上面的代码似乎运行良好。如果有人能帮我解决这个问题,我将不胜感激。

谢谢,
Vinod

Tk和OS X有几个问题。https://www.python.org/download/mac/tcltk/

您应该考虑更新Tcl(或使用不同的实现)或Python。

最新更新