致命的Python错误:PyImport_GetModuleDict:没有模块字典

时间:2013-07-16 14:44:23

标签: python multithreading error-handling python-module python-multithreading

我有一个调用API的脚本。为了加快脚本速度,我试图实现线程化。

下面的脚本在我处于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)

2 个答案:

答案 0 :(得分:3)

问题是,当你将它作为一个独立的脚本运行时,你在doWork中有很多守护程序线程,但是当只剩下守护程序线程时脚本将退出,所以它们都会被解释器退出所杀。当您在IDLE中以交互方式运行它时,解释器不会退出,因此您不会遇到该问题。

答案 1 :(得分:0)

这说明了此错误-https://bugs.python.org/issue26153-不确定是否适用于您的情况