Fatal Python error: PyImport_GetModuleDict: no module dictionary
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.
This explains this error - https://bugs.python.org/issue26153 - not sure if it applies to you case though