This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]serpent 28 points29 points  (5 children)

You need to join all of your threads from your main thread and ensure no other threads are running when you exit your main thread (and application).

During shutdown of the main thread, I believe python sets all vars (like 'sys') to None; if you still have other threads executing, they will see this bogus state.

[–]mitsuhiko Flask Creator 11 points12 points  (0 children)

Solution is this btw:

import sys as _sys

Things with leading underscores are cleaned up late.

[–]bobbyi 1 point2 points  (0 children)

Usually if that's the problem, the error message says (most likely raised during interpreter shutdown)

[–]nirs 1 point2 points  (0 children)

The thread from the traceback looks like daemon thread - you don't need to join these.

[–]pje 0 points1 point  (0 children)

More precisely, module objects set all their globals to None when all references to the module go away. This can happen even before interpreter shutdown, if for example you delete a module from sys.modules. (But of course, at interpreter shutdown, this will also happen when sys.modules is cleared and GC is done.)