This is pretty common when using daemon threads. Why are you setting .daemon = True
on your threads? Think about it. While there are legitimate uses for daemon threads, most times a programmer does it because they're confused, as in "I don't know how to shut my threads down cleanly, and the program will freeze on exit if I don't, so I know! I'll say they're daemon threads. Then the interpreter won't wait for them to terminate when it exits. Problem solved."
But it isn't solved - it usually just creates other problems. In particular, the daemon threads keep on running while the interpreter is - on exit - destroying itself. Modules are destroyed, stdin and stdout and stderr are destroyed, etc etc. All sorts of things can go wrong in daemon threads then, as the stuff they try to access is annihilated.
The specific message you're seeing is produced when an exception is raised in some thread, but interpreter destruction has gotten so far that even the sys
module no longer contains anything usable. The threading implementation retains a reference to sys.stderr
internally so that it can tell you something then (specifically, the exact message you're seeing), but too much of the interpreter has been destroyed to tell you anything else about what went wrong.
So find a way to shut down your threads cleanly instead (and remove .daemon = True
). Don't know enough about your problem to suggest a specific way, but you'll think of something ;-)
BTW, I'd suggest removing the maxsize=0
arguments on your Queue()
constructors. The default is "unbounded", and "everyone knows that", while few people know that maxsize=0
also means "unbounded". That's gotten worse as other datatypes have taken maxsize=0
to mean "maximum size really is 0" (the best example of that is collections.deque
); but "no argument means unbounded" is still universally true.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…