Python traceback.print_exception() Examples
The following are 30
code examples of traceback.print_exception().
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
traceback
, or try the search function
.

Example #1
Source File: __init__.py From jawfish with MIT License | 6 votes |
def handleError(self, record): """ Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method. """ if raiseExceptions and sys.stderr: # see issue 13807 ei = sys.exc_info() try: traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr) sys.stderr.write('Logged from file %s, line %s\n' % ( record.filename, record.lineno)) except IOError: #pragma: no cover pass # see issue 5971 finally: del ei
Example #2
Source File: __init__.py From jawfish with MIT License | 6 votes |
def emit(self, record): """ Emit a record. If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an 'encoding' attribute, it is used to determine how to do the output to the stream. """ try: msg = self.format(record) stream = self.stream stream.write(msg) stream.write(self.terminator) self.flush() except (KeyboardInterrupt, SystemExit): #pragma: no cover raise except: self.handleError(record)
Example #3
Source File: parallel.py From pygrametl with BSD 2-Clause "Simplified" License | 6 votes |
def _getexcepthook(): "Return a function that can be used as except hook for uncaught exceptions." if not sys.argv[0]: # We are in interactive mode and don't want to terminate return sys.excepthook # else create a function that terminates all spawned processes and this # in case of an uncaught exception exit = _getexitfunction() def excepthook(exctype, excvalue, exctraceback): import traceback sys.stderr.write( "An uncaught exception occured. Terminating pygrametl.\n") traceback.print_exception(exctype, excvalue, exctraceback) exit() return excepthook # Stuff for @splitpoint
Example #4
Source File: bot.py From discord.py with MIT License | 6 votes |
def on_command_error(self, context, exception): """|coro| The default command error handler provided by the bot. By default this prints to :data:`sys.stderr` however it could be overridden to have a different implementation. This only fires if you do not specify any listeners for command error. """ if self.extra_events.get('on_command_error', None): return if hasattr(context.command, 'on_error'): return cog = context.cog if cog: if Cog._get_overridden_method(cog.cog_command_error) is not None: return print('Ignoring exception in command {}:'.format(context.command), file=sys.stderr) traceback.print_exception(type(exception), exception, exception.__traceback__, file=sys.stderr) # global check registration
Example #5
Source File: util.py From mqttwarn with Eclipse Public License 2.0 | 6 votes |
def exception_traceback(exc_info=None): """ Return a string containing a traceback message for the given exc_info tuple (as returned by sys.exc_info()). from setuptools.tests.doctest """ if not exc_info: exc_info = sys.exc_info() # Get a traceback message. excout = StringIO() exc_type, exc_val, exc_tb = exc_info traceback.print_exception(exc_type, exc_val, exc_tb, file=excout) return excout.getvalue()
Example #6
Source File: report.py From segpy with GNU Affero General Public License v3.0 | 6 votes |
def main(argv=None): if argv is None: argv = sys.argv[1:] try: in_filename = argv[0] except IndexError: print(globals()['__doc__'], file=sys.stderr) return os.EX_USAGE try: report_segy(in_filename) except (FileNotFoundError, IsADirectoryError) as e: print(e, file=sys.stderr) return os.EX_NOINPUT except PermissionError as e: print(e, file=sys.stderr) return os.EX_NOPERM except Exception as e: traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) return os.EX_SOFTWARE return os.EX_OK
Example #7
Source File: custom_header.py From segpy with GNU Affero General Public License v3.0 | 6 votes |
def main(argv=None): if argv is None: argv = sys.argv[1:] try: in_filename = argv[0] except IndexError: print(globals()['__doc__'], file=sys.stderr) return os.EX_USAGE try: report_segy(in_filename) except (FileNotFoundError, IsADirectoryError) as e: print(e, file=sys.stderr) return os.EX_NOINPUT except PermissionError as e: print(e, file=sys.stderr) return os.EX_NOPERM except Exception as e: traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) return os.EX_SOFTWARE return os.EX_OK
Example #8
Source File: scale_source_coords.py From segpy with GNU Affero General Public License v3.0 | 6 votes |
def main(argv=None): if argv is None: argv = sys.argv[1:] try: scale_factor = float(argv[0]) in_filename = argv[1] out_filename = argv[2] except (ValueError, IndexError): print(globals()['__doc__'], file=sys.stderr) return os.EX_USAGE try: transform(scale_factor, in_filename, out_filename) except (FileNotFoundError, IsADirectoryError) as e: print(e, file=sys.stderr) return os.EX_NOINPUT except PermissionError as e: print(e, file=sys.stderr) return os.EX_NOPERM except Exception as e: traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) return os.EX_SOFTWARE return os.EX_OK
Example #9
Source File: loadsave.py From segpy with GNU Affero General Public License v3.0 | 6 votes |
def main(argv=None): if argv is None: argv = sys.argv[1:] try: in_filename = argv[0] out_filename = argv[1] except IndexError: print(globals()['__doc__'], file=sys.stderr) return os.EX_USAGE try: load_save(in_filename, out_filename) except (FileNotFoundError, IsADirectoryError) as e: print(e, file=sys.stderr) return os.EX_NOINPUT except PermissionError as e: print(e, file=sys.stderr) return os.EX_NOPERM except Exception as e: traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) return os.EX_SOFTWARE return os.EX_OK
Example #10
Source File: scale_samples.py From segpy with GNU Affero General Public License v3.0 | 6 votes |
def main(argv=None): if argv is None: argv = sys.argv[1:] try: scale_factor = float(argv[0]) in_filename = argv[1] out_filename = argv[2] except (ValueError, IndexError): print(globals()['__doc__'], file=sys.stderr) return os.EX_USAGE try: transform(scale_factor, in_filename, out_filename) except (FileNotFoundError, IsADirectoryError) as e: print(e, file=sys.stderr) return os.EX_NOINPUT except PermissionError as e: print(e, file=sys.stderr) return os.EX_NOPERM except Exception as e: traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) return os.EX_SOFTWARE return os.EX_OK
Example #11
Source File: timed_reader.py From segpy with GNU Affero General Public License v3.0 | 6 votes |
def main(argv=None): if argv is None: argv = sys.argv[1:] try: in_filename = argv[0] except IndexError: print(globals()['__doc__'], file=sys.stderr) return os.EX_USAGE try: read_traces(in_filename) except (FileNotFoundError, IsADirectoryError) as e: print(e, file=sys.stderr) return os.EX_NOINPUT except PermissionError as e: print(e, file=sys.stderr) return os.EX_NOPERM except Exception as e: traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) return os.EX_SOFTWARE return os.EX_OK
Example #12
Source File: configuration_manager.py From panoptes with Apache License 2.0 | 6 votes |
def _setup_logging(self, config): log_config_file = config[u'log'][u'config_file'] self._logger.info(u'Logging configuration file: ' + log_config_file) try: logging.config.fileConfig(log_config_file) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stderr) raise PanoptesConfigurationError( u'Could not instantiate logger with logging configuration provided in file "%s": (%s) %s' % ( log_config_file, exc_type, exc_value)) # Create a filter to rate limit logs so that a misconfiguration or failure does not make the disk I/O go # beserk or fill up the disk space. We do this in code instead if configuration for two reasons: # - It enforces a filter on every handler, so no chance of messing them up in configuration # - We use fileConfig (nof dictConfig) to setup our logging and fileConfig does not support filter configuration throttle = RateLimitingFilter(rate=config[u'log'][u'rate'], per=config[u'log'][u'per'], burst=config[u'log'][u'burst']) # Apply the filter to all handlers. Note that this would be a shared filter across ALL logs generated by this # process and thus the rate/burst should be set appropriately high for handler in logging._handlerList: # _handlerList is a list of weakrefs, so the object returned has to be dereferenced handler().addFilter(throttle)
Example #13
Source File: __init__.py From meddle with MIT License | 6 votes |
def handleError(self, record): """ Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method. """ if raiseExceptions: ei = sys.exc_info() try: traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr) sys.stderr.write('Logged from file %s, line %s\n' % ( record.filename, record.lineno)) except IOError: pass # see issue 5971 finally: del ei
Example #14
Source File: __init__.py From ironpython2 with Apache License 2.0 | 6 votes |
def handleError(self, record): """ Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method. """ if raiseExceptions and sys.stderr: # see issue 13807 ei = sys.exc_info() try: traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr) sys.stderr.write('Logged from file %s, line %s\n' % ( record.filename, record.lineno)) except IOError: pass # see issue 5971 finally: del ei
Example #15
Source File: util.py From ironpython2 with Apache License 2.0 | 6 votes |
def _Invoke_(self, dispid, lcid, wFlags, args): print "In Invoke with", dispid, lcid, wFlags, args, "with object",self.policy._obj_ try: rc = win32com.server.policy.DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args) # print "Invoke of", dispid, "returning", rc return rc except Exception: t, v, tb = sys.exc_info() tb = None # A cycle scode = v.scode try: desc = " (" + str(v.description) + ")" except AttributeError: desc = "" print "*** Invoke of %s raised COM exception 0x%x%s" % (dispid, scode, desc) except: print "*** Invoke of %s failed:" % dispid typ, val, tb = sys.exc_info() import traceback traceback.print_exception(typ, val, tb) raise
Example #16
Source File: inject.py From pyringe with Apache License 2.0 | 6 votes |
def InjectString(self, codestring, wait_for_completion=True): """Try to inject python code into current thread. Args: codestring: Python snippet to execute in inferior. (may contain newlines) wait_for_completion: Block until execution of snippet has completed. """ if self.inferior.is_running and self.inferior.gdb.IsAttached(): try: self.inferior.gdb.InjectString( self.inferior.position, codestring, wait_for_completion=wait_for_completion) except RuntimeError: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) else: logging.error('Not attached to any process.')
Example #17
Source File: __init__.py From BinderFilter with MIT License | 6 votes |
def handleError(self, record): """ Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method. """ if raiseExceptions and sys.stderr: # see issue 13807 ei = sys.exc_info() try: traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr) sys.stderr.write('Logged from file %s, line %s\n' % ( record.filename, record.lineno)) except IOError: pass # see issue 5971 finally: del ei
Example #18
Source File: run.py From BinderFilter with MIT License | 6 votes |
def runcode(self, code): global interruptable try: self.usr_exc_info = None interruptable = True try: exec code in self.locals finally: interruptable = False except SystemExit: # Scripts that raise SystemExit should just # return to the interactive prompt pass except: self.usr_exc_info = sys.exc_info() if quitting: exit() print_exception() jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>") if jit: self.rpchandler.interp.open_remote_stack_viewer() else: flush_stdout()
Example #19
Source File: log.py From open_dnsdb with Apache License 2.0 | 6 votes |
def formatException(self, exc_info, record=None): """Format exception output with CONF.logging_exception_prefix.""" if not record: return logging.Formatter.formatException(self, exc_info) stringbuffer = moves.StringIO() traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], None, stringbuffer) lines = stringbuffer.getvalue().split('\n') stringbuffer.close() if CONF.logging_exception_prefix.find('%(asctime)') != -1: record.asctime = self.formatTime(record, self.datefmt) formatted_lines = [] for line in lines: pl = CONF.logging_exception_prefix % record.__dict__ fl = '%s%s' % (pl, line) formatted_lines.append(fl) return '\n'.join(formatted_lines)
Example #20
Source File: __init__.py From Computable with MIT License | 6 votes |
def handleError(self, record): """ Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method. """ if raiseExceptions: ei = sys.exc_info() try: traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr) sys.stderr.write('Logged from file %s, line %s\n' % ( record.filename, record.lineno)) except IOError: pass # see issue 5971 finally: del ei
Example #21
Source File: __main__.py From pydeface with MIT License | 6 votes |
def setup_exceptionhook(): """ Overloads default sys.excepthook with our exceptionhook handler. If interactive, our exceptionhook handler will invoke pdb.post_mortem; if not interactive, then invokes default handler. """ def _pdb_excepthook(type, value, tb): if is_interactive(): import traceback import pdb traceback.print_exception(type, value, tb) # print() pdb.post_mortem(tb) else: lgr.warn( "We cannot setup exception hook since not in interactive mode") sys.excepthook = _pdb_excepthook
Example #22
Source File: __init__.py From oss-ftp with MIT License | 6 votes |
def handleError(self, record): """ Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method. """ if raiseExceptions and sys.stderr: # see issue 13807 ei = sys.exc_info() try: traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr) sys.stderr.write('Logged from file %s, line %s\n' % ( record.filename, record.lineno)) except IOError: pass # see issue 5971 finally: del ei
Example #23
Source File: run.py From oss-ftp with MIT License | 6 votes |
def print_exception(): import linecache linecache.checkcache() flush_stdout() efile = sys.stderr typ, val, tb = excinfo = sys.exc_info() sys.last_type, sys.last_value, sys.last_traceback = excinfo tbe = traceback.extract_tb(tb) print>>efile, '\nTraceback (most recent call last):' exclude = ("run.py", "rpc.py", "threading.py", "Queue.py", "RemoteDebugger.py", "bdb.py") cleanup_traceback(tbe, exclude) traceback.print_list(tbe, file=efile) lines = traceback.format_exception_only(typ, val) for line in lines: print>>efile, line,
Example #24
Source File: run.py From oss-ftp with MIT License | 6 votes |
def runcode(self, code): global interruptable try: self.usr_exc_info = None interruptable = True try: exec code in self.locals finally: interruptable = False except SystemExit: # Scripts that raise SystemExit should just # return to the interactive prompt pass except: self.usr_exc_info = sys.exc_info() if quitting: exit() print_exception() jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>") if jit: self.rpchandler.interp.open_remote_stack_viewer() else: flush_stdout()
Example #25
Source File: __init__.py From jawfish with MIT License | 5 votes |
def formatException(self, ei): """ Format and return the specified exception information as a string. This default implementation just uses traceback.print_exception() """ sio = io.StringIO() tb = ei[2] # See issues #9427, #1553375. Commented out for now. #if getattr(self, 'fullstack', False): # traceback.print_stack(tb.tb_frame.f_back, file=sio) traceback.print_exception(ei[0], ei[1], tb, None, sio) s = sio.getvalue() sio.close() if s[-1:] == "\n": s = s[:-1] return s
Example #26
Source File: doctest_driver.py From razzy-spinner with GNU General Public License v3.0 | 5 votes |
def _exception_traceback(exc_info): excout = StringIO() exc_type, exc_val, exc_tb = exc_info traceback.print_exception(exc_type, exc_val, exc_tb, file=excout) return excout.getvalue()
Example #27
Source File: __main__.py From jwalk with Apache License 2.0 | 5 votes |
def debug_hook(type_, value, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty(): sys.__excepthook__(type_, value, tb) else: import traceback import pdb traceback.print_exception(type_, value, tb) print(u"\n") pdb.pm()
Example #28
Source File: data_process.py From 3D-R2N2 with MIT License | 5 votes |
def print_error(func): '''Flush out error messages. Mainly used for debugging separate processes''' def func_wrapper(*args, **kwargs): try: return func(*args, **kwargs) except: traceback.print_exception(*sys.exc_info()) sys.stdout.flush() return func_wrapper
Example #29
Source File: ptinstaller.py From pythonista-tools-installer with MIT License | 5 votes |
def _install(self, btn): self.activity_indicator.start() install_path = PythonistaToolsInstaller.get_install_path() target_folder = PythonistaToolsInstaller.get_target_folder(btn.category_name, btn.tool_name) try: if self.gist_installer.get_gist_id(btn.tool_url): if not os.path.exists(target_folder): os.makedirs(target_folder) self.gist_installer.install(btn.tool_url, target_folder) elif self.github_installer.get_github_user_repo(btn.tool_url): if not os.path.exists(target_folder): os.makedirs(target_folder) self.github_installer.install(btn.tool_url, target_folder) else: # any other url types, including iTunes webbrowser.open(btn.tool_url) btn.set_state_uninstall() console.hud_alert('%s installed at %s' % (btn.tool_name, install_path), 'success', 1.0) except Exception as e: # clean up the directory if os.path.exists(target_folder): shutil.rmtree(target_folder) btn.set_state_install() # revert the state # Display some debug messages etype, evalue, tb = sys.exc_info() sys.stderr.write('%s\n' % repr(e)) import traceback traceback.print_exception(etype, evalue, tb) console.hud_alert('Installation failed', 'error', 1.0) finally: self.activity_indicator.stop()
Example #30
Source File: __main__.py From link-prediction_with_deep-learning with MIT License | 5 votes |
def debug(type_, value, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty(): sys.__excepthook__(type_, value, tb) else: import traceback import pdb traceback.print_exception(type_, value, tb) print(u"\n") pdb.pm()