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

问题描述 投票:10回答:2

我有一个调用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)
python multithreading error-handling python-module python-multithreading
2个回答
3
投票

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


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.