2015-02-23 60 views
0

我已經有一個應用程序使用tkMessageBox模塊,多處理模塊和urllib2模塊。由於某些未知的原因,python子進程在獲取url時會自動崩潰。這僅在導入tkMessageBox模塊時纔會發生。MacOSX Python子進程運行urlopen在導入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 & 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和Windows 7上面的代碼似乎工作正常。如果有人能幫我解決這個問題,我將不勝感激。

感謝,
維諾德

回答

0

有幾個問題TK和OS X. https://www.python.org/download/mac/tcltk/

你應該考慮更新您的Tcl(或使用不同的實現)或Python。

+0

謝謝尤金。我已經從活動狀態更新了我的tcl版本到8.5.17。沒有運氣。雖然最新版本是8.6.x版本,但它不能用於MacOS上的python,原因如下:http://stackoverflow.com/questions/21129498/idle-warns-against-an-old-tcl-version-即使安裝了新版本 – 2015-02-24 00:49:01

+0

您是否需要使用Tk?看來Tk在OSX上功能不是很好。 http://wiki.tcl.tk/1013上的郵件列表可以幫助你。 – 2015-02-24 17:20:49