10

我有一個調用API的腳本。爲了加速腳本,我試圖實現線程。致命的Python錯誤:PyImport_GetModuleDict:無模塊字典

下面的腳本在IDLE中工作,但是當我嘗試使用命令行中的sys argv運行它時,我收到了下面列出的兩種類型的錯誤。

錯誤1

Fatal Python error: PyImport_GetModuleDict: no module dictionary! 

This application has requests the Runtime to terminate it in an unusual way. Please   contact the application's support team for more information. 

錯誤2

Exception in thread Thread-1 (most likely raised during iterpreter shutdown): 
Exception in thread Thread-2 (most likely raised during iterpreter shutdown): 
Exception in thread Thread-3 (most likely raised during iterpreter shutdown): 
Exception in thread Thread-5 (most likely raised during iterpreter shutdown): 

我無法找到這些錯誤東西。所以,任何幫助表示讚賞。以下是處理線程的腳本部分。

import threading 
import diffbot 

urls = [[example.com],[example2.com]] 
data = [] 

def getData(url): 
     x = diffbot.classify(url) 
    data.append(x) 


def doWork(urls): 
    for element in urls: 
     for url in element: 
      t = threading.Thread(target=getData, args=(url,)) 
      t.daemon = True 
      t.start() 

doWork(urls) 
+0

從谷歌搜索第一個錯誤消息我猜你在Windows上。我會添加這些信息(也可以標記「windows」問題)。還要補充:你正在運行的Python版本,運行腳本的方式,其他Python腳本是否正常運行,交互使用diffbot(即在Python shell中)是否引發錯誤... –

回答

3

的問題是,當你運行這個作爲一個獨立的腳本,你有很多的doWork守護線程的,但只有守護線程離開時,該腳本將退出,所以他們都得到解釋者殺害退出。當你在IDLE中交互式運行它時,解釋器不會退出,所以你不會遇到這個問題。