I am doing some gnarly stuff with Python threads including daemons.
I am getting an intermittent error on some tests:
Exception in thread myconsumerthread (most likely raised during interpreter shutdown):
Note that there are no stack trace/exception details provided.
Scrutinising my own code hasn't helped, but I am at a bit of a loss about the next step in debugging. What debugging techniques can I use to find out more about what exception might be bringing down the runtime during shutdown?
Fine print:
- Windows, CPython, 2.7.2 - Not reproduceable on Ubuntu.
- The problem occurs about 3% of the time - so reproducable, just not reliably.
- The code in myconsumerthread has a catch-all exception handler, which tries to write the name of the exception to
sys.stderr
. (Couldsys
already be shut-down?) - I suspect the problem is related to shutting down daemon threads very quickly; before they have completely initialised. Something in this area, but I have little evidence - certainly insufficient to be pointing at a Python bug.
- Ha, I have discovered a new symptom that marks a turning point in my descent into insanity!
- If I
import time
in my test harness (not the live code), and never use it, the frequency drops to about 0.5%. - If I
import turtle
in my test harness (I swear on my life, there are no turtle graphics in my code; I chose this as the most irrelevant library I could quickly find) the exception starts to be caught in a different thread, and it occurs in about a third of the runs.
- If I