From e06fc101f5ba2e1313de0f33bc9f56b91b1a4611 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Wed, 13 Sep 2017 22:13:50 -0700 Subject: [PATCH] Add function to enable faulthandler on all threads --- pyqtgraph/debug.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pyqtgraph/debug.py b/pyqtgraph/debug.py index 0da24d7c..61ae9fd5 100644 --- a/pyqtgraph/debug.py +++ b/pyqtgraph/debug.py @@ -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 +