This is a code from threading.py module:
import sys as _sys
class Thread(_Verbose):
def _bootstrap_inner(self):
# some code
# If sys.stderr is no more (most likely from interpreter
# shutdown) use self._stderr. Otherwise still use sys (as in
# _sys) in case sys.stderr was redefined since the creation of
# self.
if _sys:
_sys.stderr.write("Exception in thread %s:\n%s\n" %
(self.name, _format_exc()))
else:
# some code
might be helpful. The error you see comes from else
statement. So in your case:
import sys as _sys
while True:
if not _sys:
break/return/die/whatever
do_something()
time.sleep(interval)
I'm not sure if it works though (note that interpreter shutdown may happen inside do_something
so you should probably wrap everything with try:except:
).
Daemon threads are not necessarily bad, they can definitely speed up development process. You just have to be careful with them.