Python faulthandler.dump_traceback() Examples
The following are 24
code examples of faulthandler.dump_traceback().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
faulthandler
, or try the search function
.
Example #1
Source File: CrashHandler.py From Cura with GNU Lesser General Public License v3.0 | 9 votes |
def _logInfoWidget(self): group = QGroupBox() group.setTitle(catalog.i18nc("@title:groupbox", "Logs")) layout = QVBoxLayout() text_area = QTextEdit() tmp_file_fd, tmp_file_path = tempfile.mkstemp(prefix = "cura-crash", text = True) os.close(tmp_file_fd) with open(tmp_file_path, "w", encoding = "utf-8") as f: faulthandler.dump_traceback(f, all_threads=True) with open(tmp_file_path, "r", encoding = "utf-8") as f: logdata = f.read() text_area.setText(logdata) text_area.setReadOnly(True) layout.addWidget(text_area) group.setLayout(layout) self.data["log"] = logdata return group
Example #2
Source File: rl_trainer.py From trax with Apache License 2.0 | 6 votes |
def main(argv): del argv logging.info('Starting RL training.') gin_configs = FLAGS.config or [] gin.parse_config_files_and_bindings(FLAGS.config_file, gin_configs) logging.info('Gin cofig:') logging.info(gin_configs) train_rl( output_dir=FLAGS.output_dir, train_batch_size=FLAGS.train_batch_size, eval_batch_size=FLAGS.eval_batch_size, trajectory_dump_dir=(FLAGS.trajectory_dump_dir or None), ) # TODO(afrozm): This is for debugging. logging.info('Dumping stack traces of all stacks.') faulthandler.dump_traceback(all_threads=True) logging.info('Training is done, should exit.')
Example #3
Source File: test_concurrent_futures.py From android_universal with MIT License | 6 votes |
def _fail_on_deadlock(self, executor): # If we did not recover before TIMEOUT seconds, consider that the # executor is in a deadlock state and forcefully clean all its # composants. import faulthandler from tempfile import TemporaryFile with TemporaryFile(mode="w+") as f: faulthandler.dump_traceback(file=f) f.seek(0) tb = f.read() for p in executor._processes.values(): p.terminate() # This should be safe to call executor.shutdown here as all possible # deadlocks should have been broken. executor.shutdown(wait=True) print(f"\nTraceback:\n {tb}", file=sys.__stderr__) self.fail(f"Executor deadlock:\n\n{tb}")
Example #4
Source File: test_faulthandler.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_truncate(self): maxlen = 500 func_name = 'x' * (maxlen + 50) truncated = 'x' * maxlen + '...' code = """ import faulthandler def {func_name}(): faulthandler.dump_traceback(all_threads=False) {func_name}() """ code = code.format( func_name=func_name, ) expected = [ 'Stack (most recent call first):', ' File "<string>", line 4 in %s' % truncated, ' File "<string>", line 6 in <module>' ] trace, exitcode = self.get_output(code) self.assertEqual(trace, expected) self.assertEqual(exitcode, 0)
Example #5
Source File: test_faulthandler.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_truncate(self): maxlen = 500 func_name = 'x' * (maxlen + 50) truncated = 'x' * maxlen + '...' code = """ import faulthandler def {func_name}(): faulthandler.dump_traceback(all_threads=False) {func_name}() """ code = code.format( func_name=func_name, ) expected = [ 'Stack (most recent call first):', ' File "<string>", line 4 in %s' % truncated, ' File "<string>", line 6 in <module>' ] trace, exitcode = self.get_output(code) self.assertEqual(trace, expected) self.assertEqual(exitcode, 0)
Example #6
Source File: test_faulthandler.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_truncate(self): maxlen = 500 func_name = 'x' * (maxlen + 50) truncated = 'x' * maxlen + '...' code = """ import faulthandler def {func_name}(): faulthandler.dump_traceback(all_threads=False) {func_name}() """ code = code.format( func_name=func_name, ) expected = [ 'Stack (most recent call first):', ' File "<string>", line 4 in %s' % truncated, ' File "<string>", line 6 in <module>' ] trace, exitcode = self.get_output(code) self.assertEqual(trace, expected) self.assertEqual(exitcode, 0)
Example #7
Source File: util.py From atomic-reactor with BSD 3-Clause "New" or "Revised" License | 5 votes |
def dump_stacktraces(sig, frame): dump_traceback()
Example #8
Source File: twisted.py From anchore-engine with Apache License 2.0 | 5 votes |
def render_GET(self, request): logger.info("Handling thread dump request") try: with open('/var/log/anchore/pid_{}_thread_dump-{}'.format(os.getpid(), datetime.datetime.now().isoformat()), 'w') as dest: faulthandler.dump_traceback(dest, all_threads=True) except: logger.exception('Error dumping thread frames') return b'Failed' return b'Sucess'
Example #9
Source File: glob.py From synapse with Apache License 2.0 | 5 votes |
def _threadstacks(*args, **kwargs): # pragma: no cover ''' A signal handler used to print thread stacks. ''' print(80 * '*') print('Faulthandler stack frames per thread:') faulthandler.dump_traceback() print(80 * '*')
Example #10
Source File: glob.py From synapse with Apache License 2.0 | 5 votes |
def _asynciostacks(*args, **kwargs): # pragma: no cover ''' A signal handler used to print asyncio task stacks and thread stacks. ''' print(80 * '*') print('Asyncio tasks stacks:') tasks = asyncio.all_tasks(_glob_loop) for task in tasks: task.print_stack() print(80 * '*') print('Faulthandler stack frames per thread:') faulthandler.dump_traceback() print(80 * '*')
Example #11
Source File: test_faulthandler.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_stderr_None(self): # Issue #21497: provide a helpful error if sys.stderr is None, # instead of just an attribute error: "None has no attribute fileno". with self.check_stderr_none(): faulthandler.enable() with self.check_stderr_none(): faulthandler.dump_traceback() if hasattr(faulthandler, 'dump_traceback_later'): with self.check_stderr_none(): faulthandler.dump_traceback_later(1e-3) if hasattr(faulthandler, "register"): with self.check_stderr_none(): faulthandler.register(signal.SIGUSR1)
Example #12
Source File: __init__.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def start_threads(threads, unlock=None): threads = list(threads) started = [] try: try: for t in threads: t.start() started.append(t) except: if verbose: print("Can't start %d threads, only %d threads started" % (len(threads), len(started))) raise yield finally: try: if unlock: unlock() endtime = starttime = time.time() for timeout in range(1, 16): endtime += 60 for t in started: t.join(max(endtime - time.time(), 0.01)) started = [t for t in started if t.isAlive()] if not started: break if verbose: print('Unable to join %d threads during a period of ' '%d minutes' % (len(started), timeout)) finally: started = [t for t in started if t.isAlive()] if started: faulthandler.dump_traceback(sys.stdout) raise AssertionError('Unable to join %d threads' % len(started))
Example #13
Source File: _executor_mixin.py From loky with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _check_executor_started(executor): # Submit a small job to make sure that the pool is an working state res = executor.submit(id, None) try: res.result(timeout=TIMEOUT) except TimeoutError: print('\n' * 3, res.done(), executor._call_queue.empty(), executor._result_queue.empty()) print(executor._processes) print(threading.enumerate()) from faulthandler import dump_traceback dump_traceback() executor.submit(dump_traceback).result(TIMEOUT) raise RuntimeError("Executor took too long to run basic task.")
Example #14
Source File: test_faulthandler.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_stderr_None(self): # Issue #21497: provide an helpful error if sys.stderr is None, # instead of just an attribute error: "None has no attribute fileno". with self.check_stderr_none(): faulthandler.enable() with self.check_stderr_none(): faulthandler.dump_traceback() if hasattr(faulthandler, 'dump_traceback_later'): with self.check_stderr_none(): faulthandler.dump_traceback_later(1e-3) if hasattr(faulthandler, "register"): with self.check_stderr_none(): faulthandler.register(signal.SIGUSR1)
Example #15
Source File: test_faulthandler.py From ironpython3 with Apache License 2.0 | 5 votes |
def check_dump_traceback(self, filename): """ Explicitly call dump_traceback() function and check its output. Raise an error if the output doesn't match the expected format. """ code = """ import faulthandler def funcB(): if {has_filename}: with open({filename}, "wb") as fp: faulthandler.dump_traceback(fp, all_threads=False) else: faulthandler.dump_traceback(all_threads=False) def funcA(): funcB() funcA() """ code = code.format( filename=repr(filename), has_filename=bool(filename), ) if filename: lineno = 6 else: lineno = 8 expected = [ 'Stack (most recent call first):', ' File "<string>", line %s in funcB' % lineno, ' File "<string>", line 11 in funcA', ' File "<string>", line 13 in <module>' ] trace, exitcode = self.get_output(code, filename) self.assertEqual(trace, expected) self.assertEqual(exitcode, 0)
Example #16
Source File: __init__.py From ironpython3 with Apache License 2.0 | 5 votes |
def start_threads(threads, unlock=None): threads = list(threads) started = [] try: try: for t in threads: t.start() started.append(t) except: if verbose: print("Can't start %d threads, only %d threads started" % (len(threads), len(started))) raise yield finally: try: if unlock: unlock() endtime = starttime = time.time() for timeout in range(1, 16): endtime += 60 for t in started: t.join(max(endtime - time.time(), 0.01)) started = [t for t in started if t.isAlive()] if not started: break if verbose: print('Unable to join %d threads during a period of ' '%d minutes' % (len(started), timeout)) finally: started = [t for t in started if t.isAlive()] if started: faulthandler.dump_traceback(sys.stdout) raise AssertionError('Unable to join %d threads' % len(started))
Example #17
Source File: test_faulthandler.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_stderr_None(self): # Issue #21497: provide an helpful error if sys.stderr is None, # instead of just an attribute error: "None has no attribute fileno". with self.check_stderr_none(): faulthandler.enable() with self.check_stderr_none(): faulthandler.dump_traceback() if hasattr(faulthandler, 'dump_traceback_later'): with self.check_stderr_none(): faulthandler.dump_traceback_later(1e-3) if hasattr(faulthandler, "register"): with self.check_stderr_none(): faulthandler.register(signal.SIGUSR1)
Example #18
Source File: __init__.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def start_threads(threads, unlock=None): threads = list(threads) started = [] try: try: for t in threads: t.start() started.append(t) except: if verbose: print("Can't start %d threads, only %d threads started" % (len(threads), len(started))) raise yield finally: try: if unlock: unlock() endtime = starttime = time.time() for timeout in range(1, 16): endtime += 60 for t in started: t.join(max(endtime - time.time(), 0.01)) started = [t for t in started if t.isAlive()] if not started: break if verbose: print('Unable to join %d threads during a period of ' '%d minutes' % (len(started), timeout)) finally: started = [t for t in started if t.isAlive()] if started: faulthandler.dump_traceback(sys.stdout) raise AssertionError('Unable to join %d threads' % len(started))
Example #19
Source File: util.py From atomic-reactor with BSD 3-Clause "New" or "Revised" License | 5 votes |
def dump_traceback(): frames = sys._current_frames() th_traces = [] for th_ident, frame in frames.items(): trace_entries = traceback.format_stack(frame) # Comply with faulthandler output context_str = 'Thread' if th_ident == thread.get_ident(): context_str = 'Current thread' trace_header = '%s 0x%x (most recent call first):' % (context_str, th_ident) trace_entries.append(trace_header) trace_entries.reverse() pretty_trace_entries = [s.split('\n')[0] for s in trace_entries] th_traces.append('\n'.join(pretty_trace_entries)) print('\n\n'.join(th_traces), file=sys.stderr)
Example #20
Source File: test_faulthandler.py From ironpython3 with Apache License 2.0 | 4 votes |
def check_dump_traceback_threads(self, filename): """ Call explicitly dump_traceback(all_threads=True) and check the output. Raise an error if the output doesn't match the expected format. """ code = """ import faulthandler from threading import Thread, Event import time def dump(): if {filename}: with open({filename}, "wb") as fp: faulthandler.dump_traceback(fp, all_threads=True) else: faulthandler.dump_traceback(all_threads=True) class Waiter(Thread): # avoid blocking if the main thread raises an exception. daemon = True def __init__(self): Thread.__init__(self) self.running = Event() self.stop = Event() def run(self): self.running.set() self.stop.wait() waiter = Waiter() waiter.start() waiter.running.wait() dump() waiter.stop.set() waiter.join() """ code = code.format(filename=repr(filename)) output, exitcode = self.get_output(code, filename) output = '\n'.join(output) if filename: lineno = 8 else: lineno = 10 regex = """ ^Thread 0x[0-9a-f]+ \(most recent call first\): (?: File ".*threading.py", line [0-9]+ in [_a-z]+ ){{1,3}} File "<string>", line 23 in run File ".*threading.py", line [0-9]+ in _bootstrap_inner File ".*threading.py", line [0-9]+ in _bootstrap Current thread XXX \(most recent call first\): File "<string>", line {lineno} in dump File "<string>", line 28 in <module>$ """ regex = dedent(regex.format(lineno=lineno)).strip() self.assertRegex(output, regex) self.assertEqual(exitcode, 0)
Example #21
Source File: test_faulthandler.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def check_dump_traceback(self, *, filename=None, fd=None): """ Explicitly call dump_traceback() function and check its output. Raise an error if the output doesn't match the expected format. """ code = """ import faulthandler filename = {filename!r} fd = {fd} def funcB(): if filename: with open(filename, "wb") as fp: faulthandler.dump_traceback(fp, all_threads=False) elif fd is not None: faulthandler.dump_traceback(fd, all_threads=False) else: faulthandler.dump_traceback(all_threads=False) def funcA(): funcB() funcA() """ code = code.format( filename=filename, fd=fd, ) if filename: lineno = 9 elif fd is not None: lineno = 12 else: lineno = 14 expected = [ 'Stack (most recent call first):', ' File "<string>", line %s in funcB' % lineno, ' File "<string>", line 17 in funcA', ' File "<string>", line 19 in <module>' ] trace, exitcode = self.get_output(code, filename, fd) self.assertEqual(trace, expected) self.assertEqual(exitcode, 0)
Example #22
Source File: test_faulthandler.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def check_dump_traceback_threads(self, filename): """ Call explicitly dump_traceback(all_threads=True) and check the output. Raise an error if the output doesn't match the expected format. """ code = """ import faulthandler from threading import Thread, Event import time def dump(): if {filename}: with open({filename}, "wb") as fp: faulthandler.dump_traceback(fp, all_threads=True) else: faulthandler.dump_traceback(all_threads=True) class Waiter(Thread): # avoid blocking if the main thread raises an exception. daemon = True def __init__(self): Thread.__init__(self) self.running = Event() self.stop = Event() def run(self): self.running.set() self.stop.wait() waiter = Waiter() waiter.start() waiter.running.wait() dump() waiter.stop.set() waiter.join() """ code = code.format(filename=repr(filename)) output, exitcode = self.get_output(code, filename) output = '\n'.join(output) if filename: lineno = 8 else: lineno = 10 regex = """ ^Thread 0x[0-9a-f]+ \(most recent call first\): (?: File ".*threading.py", line [0-9]+ in [_a-z]+ ){{1,3}} File "<string>", line 23 in run File ".*threading.py", line [0-9]+ in _bootstrap_inner File ".*threading.py", line [0-9]+ in _bootstrap Current thread XXX \(most recent call first\): File "<string>", line {lineno} in dump File "<string>", line 28 in <module>$ """ regex = dedent(regex.format(lineno=lineno)).strip() self.assertRegex(output, regex) self.assertEqual(exitcode, 0)
Example #23
Source File: test_faulthandler.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def check_dump_traceback_threads(self, filename): """ Call explicitly dump_traceback(all_threads=True) and check the output. Raise an error if the output doesn't match the expected format. """ code = """ import faulthandler from threading import Thread, Event import time def dump(): if {filename}: with open({filename}, "wb") as fp: faulthandler.dump_traceback(fp, all_threads=True) else: faulthandler.dump_traceback(all_threads=True) class Waiter(Thread): # avoid blocking if the main thread raises an exception. daemon = True def __init__(self): Thread.__init__(self) self.running = Event() self.stop = Event() def run(self): self.running.set() self.stop.wait() waiter = Waiter() waiter.start() waiter.running.wait() dump() waiter.stop.set() waiter.join() """ code = code.format(filename=repr(filename)) output, exitcode = self.get_output(code, filename) output = '\n'.join(output) if filename: lineno = 8 else: lineno = 10 regex = """ ^Thread 0x[0-9a-f]+ \(most recent call first\): (?: File ".*threading.py", line [0-9]+ in [_a-z]+ ){{1,3}} File "<string>", line 23 in run File ".*threading.py", line [0-9]+ in _bootstrap_inner File ".*threading.py", line [0-9]+ in _bootstrap Current thread XXX \(most recent call first\): File "<string>", line {lineno} in dump File "<string>", line 28 in <module>$ """ regex = dedent(regex.format(lineno=lineno)).strip() self.assertRegex(output, regex) self.assertEqual(exitcode, 0)
Example #24
Source File: test_faulthandler.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def check_dump_traceback(self, *, filename=None, fd=None): """ Explicitly call dump_traceback() function and check its output. Raise an error if the output doesn't match the expected format. """ code = """ import faulthandler filename = {filename!r} fd = {fd} def funcB(): if filename: with open(filename, "wb") as fp: faulthandler.dump_traceback(fp, all_threads=False) elif fd is not None: faulthandler.dump_traceback(fd, all_threads=False) else: faulthandler.dump_traceback(all_threads=False) def funcA(): funcB() funcA() """ code = code.format( filename=filename, fd=fd, ) if filename: lineno = 9 elif fd is not None: lineno = 12 else: lineno = 14 expected = [ 'Stack (most recent call first):', ' File "<string>", line %s in funcB' % lineno, ' File "<string>", line 17 in funcA', ' File "<string>", line 19 in <module>' ] trace, exitcode = self.get_output(code, filename, fd) self.assertEqual(trace, expected) self.assertEqual(exitcode, 0)