Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal Python error: PyImport_GetModuleDict: no module dictionary

I have a script that makes calls to an API. In order to speed the script up I've tried to implement threading.

The script below works when I'm in IDLE, however when I try to run it with a sys argv from the command line I received two types of errors listed below.

Error 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.

Error 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):

I can't find anything on these errors. So, any help is appreciated. Below is the portion of the script that deals with threading.

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)
like image 309
cloud36 Avatar asked Jul 16 '13 14:07

cloud36


1 Answers

The problem is that when you run this as a stand alone script you have a lot of daemon threads in doWork, but the script will exit when only daemon threads are left, so they all get killed by the interpreter exiting. When you run it interactively in IDLE the interpreter doesn't exit, so you don't run into that problem.

like image 80
Eric Renouf Avatar answered Nov 11 '22 16:11

Eric Renouf