Skip to content

Commit

Permalink
Ignore assertions from python threading when looking for leaked threads.
Browse files Browse the repository at this point in the history
While looking for leaked resources (threads) after shutdown and before restart
we in some cases get an assertion in the python threading module where we find
a thread marked as running at the python level but it has no associated thread
at the C level.
  • Loading branch information
jaharkes committed May 22, 2016
1 parent a28196d commit ceb0ec5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions homeassistant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,18 @@ def try_to_restart():
# Count remaining threads, ideally there should only be one non-daemonized
# thread left (which is us). Nothing we really do with it, but it might be
# useful when debugging shutdown/restart issues.
nthreads = sum(thread.isAlive() and not thread.isDaemon()
for thread in threading.enumerate())
if nthreads > 1:
sys.stderr.write("Found {} non-daemonic threads.\n".format(nthreads))
try:
nthreads = sum(thread.isAlive() and not thread.isDaemon()
for thread in threading.enumerate())
if nthreads > 1:
sys.stderr.write(
"Found {} non-daemonic threads.\n".format(nthreads))

# Somehow we sometimes seem to trigger an assertion in the python threading
# module. It seems we find threads that have no associated OS level thread
# which are not marked as stopped at the python level.
except AssertionError:
sys.stderr.write("Failed to count non-daemonic threads.\n")

# Send terminate signal to all processes in our process group which
# should be any children that have not themselves changed the process
Expand Down

0 comments on commit ceb0ec5

Please sign in to comment.