Add function to enable faulthandler on all threads

This commit is contained in:
Luke Campagnola 2017-09-13 22:13:50 -07:00
parent 6d05a2f8e1
commit e06fc101f5
1 changed files with 20 additions and 0 deletions

View File

@ -1186,3 +1186,23 @@ class ThreadColor(object):
c = (len(self.colors) % 15) + 1
self.colors[tid] = c
return self.colors[tid]
def enableFaulthandler():
""" Enable faulthandler for all threads.
If the faulthandler package is available, this function disables and then
re-enables fault handling for all threads (this is necessary to ensure any
new threads are handled correctly), and returns True.
If faulthandler is not available, then returns False.
"""
try:
import faulthandler
# necessary to disable first or else new threads may not be handled.
faulthandler.disable()
faulthandler.enable(all_threads=True)
return True
except ImportError:
return False