def _exception_cb(self, typ, value, tb): if hasattr(sys, "ps1") or not sys.stderr.isatty(): # we are in interactive mode or we don't have a tty-like # device, so we call the default hook sys.__excepthook__(type, value, tb) else: import traceback, pdb msg = gtk.MessageDialog( parent=ctx.main_window, flags=gtk.DIALOG_MODAL, type=gtk.MESSAGE_ERROR, message_format="Exception! Look at console for debugging.", ) msg.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK) msg.run() msg.destroy() print color_bright_red traceback.print_exception(type, value, tb) print color_none print # ...then start the debugger in post-mortem mode. print color_bright_blue pdb.pm() print color_none
def excepthook(type,value,tb): import traceback, pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(type, value, tb) print # ...then start the debugger in post-mortem mode. pdb.pm()
def append_exception(self, message=u''): """Appends the current exception to the exceptions of this widget. This will be shown to the user next to the widget (or instead of the widget if this was from the draw method crashing). Do not ever let exceptions propagate so that they kill of the whole page! """ if print_exceptions: traceback.print_exc() log_id = None if Webwidgets.Utils.is_log_exceptions(): log_id = Webwidgets.Utils.log_exception() if debug_exceptions: # Uggly hack around a bug in pdb (it apparently depends on # and old sys-API) sys.last_traceback = sys.exc_info()[2] print "######################### The application has crashed ##########################" print "Exception: %s" % (sys.exc_info()[1],) pdb.pm() self.system_errors.append( {'exception': sys.exc_info()[1], 'log_id': log_id, 'message': message, 'traceback': WebUtils.HTMLForException.HTMLForException()})
def exceptions(type, value, tb) : """Called for each exception. Print the location and invoke pdb.""" import pdb import traceback traceback.print_exception(type, value, tb) print pdb.pm()
def info(type, value, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty(): sys.__excepthook__(type, value, tb) import traceback, pdb traceback.print_exception(type, value, tb) print pdb.pm()
def info(type, value, tb): from PyQt4.QtCore import pyqtRemoveInputHook for line in traceback.format_exception(type, value, tb): sys.stdout.write(line) pyqtRemoveInputHook() from pdb import pm pm()
def _except_handler(exc_class, value, tb): """ Called when an uncaught exception is raised. Depending on the current state of the interpreter, either call the old (normal) except hook or drop into the pdb debugger in post mortem mode to enable further analysis. .. versionadded:: 0.1.0 """ global old_excepthook if hasattr(sys, 'ps1') or not sys.stderr.isatty(): # We aren't in interactive mode or we don't have a tty-like device, so # we call the default hook. old_excepthook(exc_class, value, tb) else: import traceback import pdb # We are in interactive mode, print the exception... traceback.print_exception(exc_class, value, tb) print # ...then start the debugger in post-mortem mode. pdb.pm()
def process_exception(self, request, exception): if settings.DEBUG_IN_TERMINAL: import pdb, sys, traceback sys.last_traceback = sys.exc_info()[2] print "================================================================================" traceback.print_exc() pdb.pm() return None
def _debug_hook(self, exctype, value, tb): self._write_exception_hook(exctype, value, tb) traceback.print_exception(exctype, value, tb) print() print('-- Starting debugger --') print() import pdb pdb.pm()
def rowActivated(self, treeView, path, viewColumn): try: self.selectionChanged(self.updateDirCacheNumPath(path[1:], treeNode = self.model.rootNode)) except: import sys, pdb sys.last_traceback = sys.exc_info()[2] pdb.pm()
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option('-e', '--endpoint', dest='endpoint', default='ipc://zerovisor.sock', help='Specify zerovisor endpoint.') parser.add_option('-c', '--controlpoint', dest='controlpoint', default='ipc://control.sock', help='Specify zerovisor control endpoint.') parser.add_option('-s', '--syncpoint', dest='syncpoint', default='ipc://syncpoint.sock', help='Endpoint for receiving sync data.') parser.add_option('-n', '--name', dest='name', default=uuid1().hex, help="Center name. Default is a random UUID.") parser.add_option('-R', '--ring', dest='ring', default=None, help="Comma separated list of peer center endpoints.") parser.add_option('-l', '--logfile', dest='logfile', default='zerovisor.log', help='Specify the log file.') parser.add_option('-d', '--debug', action='store_true', dest='debug', default=False, help='Debug on unhandled error.') parser.add_option('-E', '--echo-sql', action='store_true', dest='echo_sql', default=False, help='Echo sql code issues when state changes.') (options, args) = parser.parse_args() logfile = sys.stdout if options.logfile != '-': logfile = open(options.logfile, 'w+') db.setup(echo=options.echo_sql) db.create_all() from sqlalchemy.orm import sessionmaker Session = sessionmaker(bind=db.engine) conn = db.engine.connect() session = Session(bind=conn) try: g = gevent.spawn( Center(session, options.name, options.endpoint, options.controlpoint, options.syncpoint, options.ring, logfile, ).start) g.join() except Exception: if options.debug: import pdb; pdb.pm() else: raise
def onKeyPress(self, actor=None, event=None, data=None): """ Basic key binding handler """ uval = event.unicode_value kval = event.keyval state = event.modifier_state log.debug('u %r v %d' % (uval, kval)) if uval != '': self.shell.write(uval) return if (state & state.MOD1_MASK == state.MOD1_MASK): # Alt key is on putting escape self.shell.write('') if kval == 65513 or kval == 65507: # Alt key will be put later return if (state & state.SHIFT_MASK == state.SHIFT_MASK): if kval in shaders: self.shader = None shaders[kval](self.linesGroup) return if kval == 65475: self.shader = apply_glsl_effect(self.linesGroup) return elif kval == 65478: from pprint import pprint pprint(self.lexer.matrix.matrix) elif kval == 65479: log.error( '\n'.join( [self.lexer.get_line(line) for line in range(self.lexer.rows)])) elif kval == 65480: import pdb pdb.pm() elif kval == 65481: import pdb pdb.set_trace() if kval in special_keys: if (state & state.CONTROL_MASK == state.CONTROL_MASK): self.shell.write(ctrl_special_keys[kval]) else: self.shell.write(special_keys[kval]) return log.warn('Unknown keyval %d' % kval)
def hinfo(type, value, tb): if hasattr(sys, 'ps1') or not (sys.stderr.isatty() and sys.stdin.isatty()) or issubclass(type, SyntaxError): '''交互模式、wutty设备、语法错误,默认处理''' sys.__excepthook__(type,value,tb) else: import traceback, pdb traceback.print_exception(type, value, tb) print pdb.pm()
def info(type, value, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty(): # call default hook we no tty available sys.__excepthook__(type, value, tb) else: import traceback, pdb traceback.print_exception(type, value, tb) # post-mortem mode pdb pdb.pm()
def info(type, value, tb): if hasattr(sys, "ps1") or not (sys.stderr.isatty() and sys.stdin.isatty()) or issubclass(type, SyntaxError): sys.__excepthook__(type, value, tb) else: import traceback, pdb traceback.print_exception(type, value, tb) print pdb.pm()
def dbghook(type, value, tb): import traceback, pdb gui_instance.except_shutdown() traceback.print_exception(type, value, tb) print pdb.pm()
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()
def invoke_pdb(type, value, tb): """ Cool feature: on crash, the debugger is invoked in the last state of the program. To Use, call in __main__: sys.excepthook = invoke_pdb """ import traceback, pdb traceback.print_exception(type, value, tb) print pdb.pm()
def excepthook(type, value, tb): if issubclass(type, SyntaxError) or hasattr(sys, 'ps1') or \ not (sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty()) : sys.__excepthook__(type, value, tb) else: import traceback, pdb traceback.print_exception(type, value, tb) print() pdb.pm()
def debugger(type, value, tb): """Hook for handling exceptions using pdb debugger. > sys.excepthook = debugger """ import sys, traceback, pdb sys.excepthook = None # detach debugger traceback.print_exception(type, value, tb) pdb.pm()
def postmortem(type, value, tb): # from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287 if hasattr(sys, 'ps1') or not ( sys.stderr.isatty() and sys.stdin.isatty()): sys.__excepthook__(type, value, tb) else: import traceback, pdb traceback.print_exception(type, value, tb) print pdb.pm()
def debug_hook(exctype, value, tb): import traceback traceback.print_exception(exctype, value, tb) print print '-- Starting debugger --' print import pdb pdb.pm() raise SystemExit
def _pdbg(_a_function_thingie, *ar, **kwa): """ Run with pdb post-mortem on exception """ import pdb try: return _a_function_thingie(*ar, **kwa) except Exception as exc: _, _, sys.last_traceback = sys.exc_info() traceback.print_exc() pdb.pm() return None
def test(): import pdb try: testproper() except: sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info() print print sys.last_type, ':', sys.last_value print pdb.pm()
def _debug(t, v, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty(): sys.__excepthook__(t, v, tb) else: import pdb import traceback traceback.print_exception(t, v, tb) print() pdb.pm() os._exit(1)
def intercept (exc_type, value, trace): interactive = os.environ.get('PDB',None) if interactive in ['0','']: # PDB was set to 0 or '' which is undocumented, and we do nothing pass else: bug_report(exc_type, value, trace) if interactive == 'true': import pdb pdb.pm()
def hinfo(type, value, tb): if hasattr(sys, 'ps1') or not (sys.stderr.isatty() and sys.stdin.isatty()) or issubclass( type, SyntaxError): '''交互模式、wutty设备、语法错误,默认处理''' sys.__excepthook__(type, value, tb) else: import traceback, pdb traceback.print_exception(type, value, tb) print pdb.pm()
def dbghook(type, value, tb): import traceback import pdb if gui_instance: gui_instance.except_shutdown() traceback.print_exception(type, value, tb) print pdb.pm()
def pdbexcepthook(type, value, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty(): # we are in interactive mode or we don't have a tty-like # device, so we call the default hook sys.__excepthook__(type, value, tb) else: import traceback, pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(type, value, tb) print # ...then start the debugger in post-mortem mode. pdb.pm()
def ExceptionHookPDB(exctype, value, tb): ''' A custom exception handler, with :py:obj:`pdb` post-mortem for debugging. ''' for line in traceback.format_exception_only(exctype, value): log.error(line.replace('\n', '')) for line in traceback.format_tb(tb): log.error(line.replace('\n', '')) sys.__excepthook__(exctype, value, tb) pdb.pm()
def test(): import pdb try: testproper() except: sys.last_type, sys.last_value, sys.last_traceback = (sys.exc_type, sys.exc_value, sys.exc_traceback) print print sys.last_type, ':', sys.last_value print pdb.pm()
def Test(): try: t = ValidateblocktemplateTest() bitcoinConf = { "debug": ["net", "blk", "thin", "mempool", "req", "bench", "evict"], # "lck" "blockprioritysize": 2000000 # we don't want any transactions rejected due to insufficient fees... } # t.main(["--tmppfx=/ramdisk/test", "--nocleanup", "--noshutdown"], bitcoinConf, None) t.main(["--tmppfx=/ramdisk/test","--nocleanup", "--noshutdown"], bitcoinConf, None) except Exception as e: print(str(e)) pdb.pm()
def debug_info(type, value, tb): # if hasattr(sys, 'ps1') or not sys.stderr.isatty() or type != AssertionError: if hasattr(sys, 'ps1') or not sys.stderr.isatty() or type == KeyboardInterrupt: # we are in interactive mode or we don't have a tty-like # device, so we call the default hook sys.__excepthook__(type, value, tb) else: # we are NOT in interactive mode, print the exception... traceback.print_exc() print # ...then start the debugger in post-mortem mode. pdb.pm()
def idb_excepthook(type, value, tb): """Call an interactive debugger in post-mortem mode If you do "sys.excepthook = idb_excepthook", then an interactive debugger will be spawned at an unhandled exception """ if hasattr(sys, 'ps1') or not sys.stderr.isatty(): sys.__excepthook__(type, value, tb) else: import pdb, traceback traceback.print_exception(type, value, tb) pdb.pm()
def info(type, value, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty(): # we are in interactive mode or we don't have a tty-like # device, so we call the default hook sys.__excepthook__(type, value, tb) else: import traceback, pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(type, value, tb) print # ...then start the debugger in post-mortem mode. pdb.pm()
def debug_fn(): try: return non_debugged_fn() except: # Uggly hack around a bug in pdb (it apparently depends on # and old sys-API) sys.last_traceback = sys.exc_info()[2] print "######################### The application has crashed ##########################" print "Exception: %s" % (sys.exc_info()[1],) pdb.pm() raise
def info(type, value, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty(): # You are in interactive mode or don't have a tty-like # device, so call the default hook sys.__execthook__(type, value, tb) else: import traceback # You are not in interactive mode; print the exception traceback.print_exception(type, value, tb) print() # ... then star the debugger in post-mortem mode pdb.pm()
def exception_hook(type, value, tb): """ Hook to drop into a debugger when an exception occurs """ if hasattr(sys, 'ps1') or not sys.stderr.isatty(): # we are intereactive or don't have a tty-like device sys.__excepthook__(type, value, tb) # We're not interactive let's debug it else: import traceback, pdb traceback.print_exception(type, value, tb) print pdb.pm()
def _handler(type, value, tb): if not flags.FLAGS.pdb or hasattr(sys, 'ps1') or not sys.stderr.isatty(): # we aren't in interactive mode or we don't have a tty-like # device, so we call the default hook old_excepthook(type, value, tb) else: import traceback import pdb # we are in interactive mode, print the exception... traceback.print_exception(type, value, tb) print # ...then start the debugger in post-mortem mode. pdb.pm()
def autodebug(type, value, tb): """ Break into the debugger on an unhandled exception. """ if hasattr(sys, "ps1") or not sys.stderr.isatty(): #we're in the repl or something. sys.__excepthook__(type, value, tb) else: import traceback, pdb traceback.print_exception(type, value, tb) print("\n") pdb.pm() return
def on_message(self, message): try: message = json.loads(message) f = getattr(self, 'on_message_%s' % message['type'], None) if f is None: f = getattr(self.application, 'on_message_%s' % message['type'], None) if f is None: raise TypeError('Invalid message type: %r' % message) self.application.ioloop.add_callback(f, message['value']) except: traceback.print_exc() pdb.pm()
def info(type, value, tb): # from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287 if hasattr(sys, 'ps1') or not (sys.stderr.isatty() and sys.stdin.isatty()): # Interactive mode, no tty-like device, or syntax error: nothing # to do but call the default hook sys.__excepthook__(type, value, tb) else: import traceback, pdb # You are NOT in interactive mode; so, print the exception... traceback.print_exception(type, value, tb) print # ... then start the debugger in post-mortem mode pdb.pm()
def cbDefault(cls, err): isTerm = consoleIsTerminal() if isTerm: err = consoleColor.bold + consoleColor.red + err + consoleColor.end print err if isTerm: r = raw_input( 'Programm paused, press any key to exit\nOr type "dbg" for starting debugger\n' ) if r and r.lower() == 'dbg': import pdb pdb.pm() sys.exit(1)
def _exception(etype, eval_, etrace): """ Wrap exception in debugger if not in tty """ if hasattr(sys, 'ps1') or not sys.stderr.isatty(): # we are in interactive mode or we don't have a tty-like # device, so we call the default hook sys.__excepthook__(etype, eval_, etrace) else: import traceback, pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(etype, eval_, etrace, limit=2, file=sys.stdout) print # ...then start the debugger in post-mortem mode. pdb.pm()
def info(type, value, tb): """?? This function is an exception hook (sys.excepthook) that automatically starts the debugger in postmortem mode if there is a tty""" if hasattr(sys, 'ps1') or not sys.stderr.isatty(): # we are in interactive mode or we don't have a tty-like # device, so we call the default hook sys.__excepthook__(type, value, tb) else: import traceback, pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(type, value, tb) print # ...then start the debugger in post-mortem mode. pdb.pm()
def post_mortem(exc_type, exc_value, exc_tb): # has a good terminal and not in interactive mode has_usable_prompt = (getattr(sys, 'ps1', None) is None and sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty()) skip_exc_types = (SyntaxError, bdb.BdbQuit, KeyboardInterrupt) if issubclass(exc_type, skip_exc_types) or not has_usable_prompt: sys.__excepthook__(exc_type, exc_value, exc_tb) else: traceback.print_exception(exc_type, exc_value, exc_tb) print pdb.pm()
def catcha(type, value, tb): print("your CATCHA caught %s" % repr(type)) if type != AssertionError: #if hasattr(sys, 'ps1') or not sys.stderr.isatty(): # we are in interactive mode or we don't have a tty-like # device, so we call the default hook sys.__excepthook__(type, value, tb) else: import traceback, pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(type, value, tb) print(">_< Good luck sorting that out") # ...then start the debugger in post-mortem mode. pdb.pm()
def intercept(dtype, value, trace): try: log.report('\nFailure report:\n---------------\n') except Exception: pass import traceback traceback.print_exception(dtype, value, trace) if os.environ.get('VYOSEXTRA_DEBUG', None) is not None: import pdb pdb.pm()
def info(type, value, tb): if hasattr(sys, 'ps1') or not ( sys.stderr.isatty() and sys.stdin.isatty() ) or issubclass(type, SyntaxError): # Interactive mode, no tty-like device, or syntax error: nothing # to do but call the default hook sys.__excepthook__(type, value, tb) else: import traceback, pdb # You are NOT in interactive mode; so, print the exception... traceback.print_exception(type, value, tb) print # ...then start the debugger in post-mortem mode pdb.pm()
def _DebugHandler(exc_class, value, tb): if not flags.FLAGS.pdb or hasattr(sys, 'ps1') or not sys.stderr.isatty(): # we aren't in interactive mode or we don't have a tty-like # device, so we call the default hook old_excepthook(exc_class, value, tb) else: # Don't impose import overhead on apps that never raise an exception. import traceback import pdb # we are in interactive mode, print the exception... traceback.print_exception(exc_class, value, tb) sys.stdout.write('\n') # ...then start the debugger in post-mortem mode. pdb.pm()
def info(type, value, tb): ontty = isatty(sys.stderr) and isatty(sys.stdout) and isatty(sys.stdin) ## if hasattr(sys, 'ps1') or not ontty or type is bdb.BdbQuit or \ ## str(value) == 'underlying C/C++ object has been deleted': if hasattr(sys, 'ps1') or not ontty or type is bdb.BdbQuit: # You are in interactive mode or don't have a tty-like # device, so call the default hook sys.__excepthook__(type, value, tb) else: import traceback, pdb # You are not in interactive mode; print the exception traceback.print_exception(type, value, tb) print() # ... then star the debugger in post-mortem mode pdb.pm()
def catch(self, environ, start_response): '''Exception catcher.''' # Log exception if self.log: self.logger.exception(self.message) # Debug if self.debug: pdb.pm() # Write HTML-formatted exception tracebacks to a file if self.htmlfile is not None: open(self.htmlfile, 'wb').write(html(sys.exc_info())) # Send HTML-formatted exception tracebacks to the browser if self.tohtml: start_response(HTTPMSG, [('Content-type', 'text/html')]) return [html(sys.exc_info())] # Return error handler return self._errapp(environ, start_response)
def debug_exception(type, value, tb): """ Provides an interactive debugging session on unhandled exceptions See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287 """ if hasattr(sys, 'ps1') or not sys.stderr.isatty() or \ not sys.stdin.isatty() or not sys.stdout.isatty() or type==SyntaxError: # Calls the default handler in interactive mode, if output is· # redirected or on syntax errors sys.__excepthook__(type, value, tb) else: import traceback, pdb traceback.print_exception(type, value, tb) print pdb.pm()
def info(type, value, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty() or \ not sys.stdin.isatty() or not sys.stdout.isatty() or \ type == SyntaxError: # there is nothing to be done on syntax errors # we are in interactive mode or we don't have a tty-like # device, so we call the default hook sys.__excepthook__(type, value, tb) else: import traceback import pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(type, value, tb) print # ...then start the debugger in post-mortem mode. pdb.pm()
def excepthook(type, value, tb): if hasattr(sys, 'ps1') \ or not (sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty()) \ or type == SyntaxError or type == KeyboardInterrupt: # we are in interactive mode or we don't have a tty-like # device, so we call the default hook oldexcepthook(type, value, tb) else: import traceback, pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(type, value, tb) print # ...then start the debugger in post-mortem mode. pdb.pm()
def info(type, value, tb): if hasattr(sys, 'psl') or not (sys.stderr.isatty() and sys.stdin.isatty()) or issubclass( type, SyntaxError): # 交互模式,没有类似TTY的设备或语法错误:什么也不做 # 只能调用默认的hook sys.__excepthook__(type, value, tb) else: import traceback, pdb # 非交互模式:因此打印异常 traceback.print_exception(type, value, tb) print # 在事后分析阶段开启调试器 pdb.pm() sys.excepthook = info
def CleanExceptHook(type, value, traceback): r""" Exit cleanly when program is killed, or jump into pdb if debugging """ if type == KeyboardInterrupt: bib_error('program killed. Exiting...') elif (not bibup.debugging or hasattr(sys, 'ps1') or not sys.stdin.isatty() or not sys.stdout.isatty() or not sys.stderr.isatty() or issubclass(type, bdb.BdbQuit) or issubclass(type, SyntaxError)): sys.__excepthook__(type, value, traceback) else: import traceback, pdb # we are NOT in interactive mode, print the exception... traceback.print_exception(type, value, tb) print() # ...then start the debugger in post-mortem mode. pdb.pm()
def get_buffer(self): """ Returns the entire buffer: samples x channels If multiple amps, signals are concatenated along the channel axis. """ self.check_connect() try: if len(self.timestamps[0]) > 0: w = np.concatenate(self.buffers, axis=1) # samples x channels t = np.array(self.timestamps).reshape(-1, 1) # samples x 1 return w, t else: return np.array([]), np.array([]) except: logger.exception('Sorry! Unexpected error occurred in get_buffer(). Dropping into a shell for debugging.') pdb.pm()