• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python traceback.extract_tb函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中traceback.extract_tb函数的典型用法代码示例。如果您正苦于以下问题:Python extract_tb函数的具体用法?Python extract_tb怎么用?Python extract_tb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了extract_tb函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: read_file

 def read_file(self, path):
     #读取存储目录日志
     if os.path.exists(path):
         try:
             history_dicts = {}
             fp = open(path, 'r')
             #数据读入缓存
             cache = fp.read()
             for line in cache.splitlines():
                 #行解析
                 self.param_check(line, history_dicts)
             fp.close()
             #上报内容
             ret = self.aggresion(history_dicts)
             if ret:
                 #上报成功将文件删除
                 os.remove(path)
         except:
             info = sys.exc_info()
             traceback.extract_tb(info[2])
             self.log.error('history error %s %s %s', info[0], info[1], path)
             return 0
     else:
         self.log.debug('history file is not exit %s', path)
         return 0
     return 1
开发者ID:net20121222,项目名称:cachetraffic,代码行数:26,代码来源:cachetraffic_historywork.py


示例2: table_reader

def table_reader(options, file_info, task_queue, error_queue, exit_event):
    try:
        db = file_info["db"]
        table = file_info["table"]
        primary_key = file_info["info"]["primary_key"]
        conn = r.connect(options["host"], options["port"], auth_key=options["auth_key"])

        if table not in r.db(db).table_list().run(conn):
            r.db(db).table_create(table, primary_key=primary_key).run(conn)

        if file_info["format"] == "json":
            json_reader(task_queue,
                        file_info["file"],
                        db, table,
                        primary_key,
                        options["fields"],
                        exit_event)
        elif file_info["format"] == "csv":
            csv_reader(task_queue,
                       file_info["file"],
                       db, table,
                       primary_key,
                       options,
                       exit_event)
        else:
            raise RuntimeError("unknown file format specified")
    except (r.RqlClientError, r.RqlDriverError, r.RqlRuntimeError) as ex:
        error_queue.put((RuntimeError, RuntimeError(ex.message), traceback.extract_tb(sys.exc_info()[2])))
    except InterruptedError:
        pass # Don't save interrupted errors, they are side-effects
    except:
        ex_type, ex_class, tb = sys.exc_info()
        error_queue.put((ex_type, ex_class, traceback.extract_tb(tb), file_info["file"]))
开发者ID:isidorn,项目名称:test2,代码行数:33,代码来源:_import.py


示例3: exec_code

 def exec_code(self, c):
     try:
         std_streams = sys.stdout, sys.stderr
         sys.stdout = StringIO.StringIO()
         sys.stderr = StringIO.StringIO()
         try:
             exec c in self.locals
         finally:
             text_out = sys.stdout.getvalue()
             text_err = sys.stderr.getvalue()
             sys.stdout, sys.stderr = std_streams
             self.output.print_to_stdout(text_out)
             self.output.print_to_stderr(text_err)
     # Include these lines to actually exit on a sys.exit() call
     # except SystemExit, value:
     #    raise SystemExit, value
     except:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         l = len(traceback.extract_tb(sys.exc_traceback))
         try:
             1 / 0
         except:
             m = len(traceback.extract_tb(sys.exc_traceback))
         type, value, tb = sys.exc_info()
         sys.last_type = exc_type
         sys.last_value = exc_value
         sys.last_traceback = exc_traceback
         tblist = traceback.extract_tb(exc_traceback)
         del tblist[:1]
         list = traceback.format_list(tblist)
         if list:
             list.insert(0, "Traceback (most recent call last):\n")
         list[len(list) :] = traceback.format_exception_only(exc_type, exc_value)
         map(self.output.print_to_stderr, list)
         return
开发者ID:baowuji,项目名称:quickpalm.future,代码行数:35,代码来源:JScrapbook.py


示例4: convert_exc_to_user_error

def convert_exc_to_user_error(exc_info, error_info, msg_args=None, nested_exc_info=None,
                              user_error_class=UserError):
    """Create a user error from an exception. exc_info is the exception info
    array returned from sys.exc_info(). The user message, error code, etc
    are taken from error_info.
    The exception type and value are stored in the developer message and the
    stack traceback used to create a context stack. If a nested exception's information
    is provided through nested_exc_info, this is addeded to the end of the context
    list.

    Here is an example of using this function.

    try:
        call_something_that_can_throw_an_exception()
    except UserError:
         # if this call can throw a user error,
         # let it propagage up
        raise
    except:
        exc_info = sys.exc_info()
        raise convert_exc_to_user_error(exc_info, errors[ERR_WSGI_SCRIPT],
                                        msg_args={'script':config_mod_wsgi_file})
    
    """
    (exc_class, exc_val, exc_tb) = exc_info
    exc_name = exc_class.__name__
    if nested_exc_info != None:
        context = traceback.extract_tb(exc_tb) + traceback.extract_tb(nested_exc_info[2])
    else:
        context = traceback.extract_tb(exc_tb)
    return user_error_class(error_info, msg_args,
                            developer_msg="%s: %s" % (exc_name, format_string(exc_val)),
                            context=context)
开发者ID:quaddra,项目名称:engage-utils,代码行数:33,代码来源:user_error.py


示例5: export_table

def export_table(host, port, auth_key, db, table, directory, fields, format, error_queue, progress_info, stream_semaphore, exit_event):
    writer = None

    try:
        conn = r.connect(host, port, auth_key=auth_key)

        table_size = r.db(db).table(table).count().run(conn)
        progress_info[1].value = table_size
        progress_info[0].value = 0
        write_table_metadata(conn, db, table, directory)

        with stream_semaphore:
            task_queue = multiprocessing.queues.SimpleQueue()
            writer = launch_writer(format, directory, db, table, fields, task_queue, error_queue)
            writer.start()

            read_table_into_queue(conn, db, table, task_queue, progress_info, exit_event)
    except (r.RqlError, r.RqlDriverError) as ex:
        error_queue.put((RuntimeError, RuntimeError(ex.message), traceback.extract_tb(sys.exc_info()[2])))
    except:
        ex_type, ex_class, tb = sys.exc_info()
        error_queue.put((ex_type, ex_class, traceback.extract_tb(tb)))
    finally:
        if writer is not None and writer.is_alive():
            task_queue.put(("exit", "event")) # Exit is triggered by sending a message with two objects
            writer.join()
        else:
            error_queue.put((RuntimeError, RuntimeError("writer unexpectedly stopped"),
                             traceback.extract_tb(sys.exc_info()[2])))
开发者ID:MiguelMoll,项目名称:vFense,代码行数:29,代码来源:_export.py


示例6: execute_plugins

	def execute_plugins(self, network, trigger, *arguments):
		for plugin in plugin_handler.all_plugins():
			try:
				if plugin.__class__.__dict__.has_key(trigger):
					# FIXME this is rather ugly, for compatiblity with pynik
					if plugin.__class__.__dict__[trigger].func_code.co_argcount == len(arguments) + 2:
						plugin.__class__.__dict__[trigger](plugin, self, *arguments) # Call without network
					elif plugin.__class__.__dict__[trigger].func_code.co_argcount == len(arguments) + 3:
						plugin.__class__.__dict__[trigger](plugin, self, *arguments, **{'network': network})
					else:
						raise NotImplementedError("Plugin '%s' argument count missmatch, was %s." % (
								plugin, plugin.__class__.__dict__[trigger].func_code.co_argcount))
			except:
				error_handler.output_message("%s %s Plugin '%s' threw exception, exinfo: '%s', traceback: '%s'" % (
						datetime.datetime.now().strftime("[%H:%M:%S]"), network,
						plugin, sys.exc_info(), traceback.extract_tb(sys.exc_info()[2])))

				if trigger != "timer_beat":
					try:
						self.tell(self.settings.admin_network, self.settings.admin_channel,
							  "%s %s Plugin '%s' threw exception, exinfo: '%s', traceback: '%s'" % (
								datetime.datetime.now().strftime("[%H:%M:%S]"), network,
								plugin, sys.exc_info(), traceback.extract_tb(sys.exc_info()[2])[::-1]))
					except:
						error_handler.output_message("%s %s Unable to send exception to admin channel, exinfo: '%s', traceback: '%s'" % (
								datetime.datetime.now().strftime("[%H:%M:%S]"), network,
								sys.exc_info(), traceback.extract_tb(sys.exc_info()[2])))
开发者ID:IcEBnd,项目名称:pyirkbot,代码行数:27,代码来源:ircbot.py


示例7: __call__

 def __call__(self, request, methodname):
   handler = self._fmap.get(methodname)
   if handler is None:
     return JSONNotFound("No method " + methodname)
   try:
     data = request.POST.get("data")
     if data:
       try:
         arguments = self._decoder.decode(data)
         # First argument is method name.
         # Allow for keyword arguments as sole argument.
         if len(arguments) == 2 and isinstance(arguments[1], dict):
           args = ()
           kwargs = arguments[1]
         else: # otherwise, use positional arguments.
           args = tuple(arguments[1:])
           kwargs = {}
       except: # error in parameter conversion
         ex, val, tb = sys.exc_info()
         tblist = traceback.extract_tb(tb)
         request.log_error("JSONDispatcher args: %s (%s)\n" % (ex, val))
         return JSONServerError(ex, val, tblist)
     else:
       args = ()
       kwargs = {}
     with GlobalRequest(request):
       rv = handler(*args, **kwargs)
     json = self._encoder.encode(rv)
     return HttpResponse(json, "application/json")
   except: # all exceptions are sent back to client.
     ex, val, tb = sys.exc_info()
     tblist = traceback.extract_tb(tb)
     del tb
     request.log_error("JSONDispatcher: %s (%s)\n" % (ex, val))
     return JSONServerError(ex, val, tblist)
开发者ID:bharathi26,项目名称:pycopia,代码行数:35,代码来源:json.py


示例8: process_exception

    def process_exception(self,request, exception):
        f = open('exception.log', 'a')
        f.write(str(exception) +  "\n")
        f.close()
        
        #print traceback.print_stack()

        # From interpretter get name that caused exception
        # 
        # Use name to query the database, get newest one, update is_good to False
        #
        # Query for benign and malicious input
        #
        # Pass these two data sets to the GA
        #
        # Handle the results to update filter

        try:
            type, value, tb = sys.exc_info()
            print type
            print value
            print traceback.extract_tb(tb)
        finally:
            del tb
            return HttpResponsePermanentRedirect(request.get_full_path().split("?")[0])
开发者ID:minniek,项目名称:EC700,代码行数:25,代码来源:middlewares.py


示例9: fogbugzOnFail

 def fogbugzOnFail(self,logfp):
     print "Creating FogBuz Ticket"
     cfp=Config(self.__fpath)
     attempts=0
     run=True
     while run is True and attempts < 3: 
         try:
             site=FogBugz(cfp.getVar("fogbugz","site","string"))
             try:
                 site.logon(cfp.getVar("fogbugz","user","string"), cfp.getVar("fogbugz","pass","string"))
                 cfp=Config(self.__fpath)
                 with open(logfp,'rb') as fp:
                     print site.new(sTitle="The Parser "+os.path.join(self.__logbase,self.__execute)+" Failed",ixPersonAssignedTo="Andy",Files={"faillog.txt":fp})
                 attempts+=1
                 run=False
             except Exception,e:
                 print str(e)
                 for frame in traceback.extract_tb(sys.exc_info()[2]):
                     print '\n'.join([str(x) for x in frame])
             finally:
                 site.logoff()
         except Exception,e:
             print str(e)
             for frame in traceback.extract_tb(sys.exc_info()[2]):
                 print '\n'.join([str(x) for x in frame])
开发者ID:asevans48,项目名称:AutomationTools,代码行数:25,代码来源:ParserController.py


示例10: test_derived_traceback

def test_derived_traceback():
    """Test python exception traceback in class derived from managed base"""
    class DerivedClass(SubClassTest):
        __namespace__ = "Python.Test.traceback"

        def foo(self):
            print (xyzname)
            return None

    import sys,traceback
    ob = DerivedClass()

    # direct call
    try:
        ob.foo()
        assert False
    except:
        e = sys.exc_info()
    assert "xyzname" in str(e[1])
    location = traceback.extract_tb(e[2])[-1]
    assert location[2] == "foo"

    # call through managed code
    try:
        FunctionsTest.test_foo(ob)
        assert False
    except:
        e = sys.exc_info()
    assert "xyzname" in str(e[1])
    location = traceback.extract_tb(e[2])[-1]
    assert location[2] == "foo"
开发者ID:filmor,项目名称:pythonnet,代码行数:31,代码来源:test_subclass.py


示例11: runPythonFuncWithPickle

def runPythonFuncWithPickle(infil):
    data = pickleLoad(infil)
    pyfil = data['path']
    method = data['method']
    params =  data['params']
    map =  data['map']
    try:
        _module = loadModule(pyfil)
        _callable = getattr(_module, method)
        if callable(_callable):
            data['result'] =  _callable(*params, **map)
        else:
            data['except'] = "Unknown method: " + method + "() in Python file '" + pyfil + "'"
    # https://docs.python.org/2/library/exceptions.html#exceptions.SyntaxError
    # https://docs.python.org/2/library/traceback.html
    except SyntaxError:
        data['except'] = "Fail to compile Python file '" + pyfil + "'"
    except AttributeError:
        data['except'] = "Unknown method: '" + method + "()' in Python file '" + pyfil + "'"
    except:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        data['except'] = repr(traceback.extract_tb(exc_traceback)[1:]).encode('unicode-escape').decode().replace("\\\\", "\\").replace("\\\\", "\\")
        data['except'] = traceback.extract_tb(exc_traceback)[1:]
    outfil = infil + '.out'
    pickleDump(data, outfil)
    return outfil
开发者ID:lapps,项目名称:org.lappsgrid.pycaller,代码行数:26,代码来源:lapps_pickle_io.py


示例12: replaceStackTrace

def replaceStackTrace(nextHandler, thisFile, type, value, tb):
	chunks = [[384, 0]]
	if len(value.args) == 0:
		resultDict = {}
		resultDict["dictId"] = u"9D6B6AA1-92FC-453E-8B9A-91D0E02A17B1"
		resultDict["stackInfo"] = traceback.extract_tb(tb)
		value.args = value.args +(resultDict, ) 
	else:
		resultDict = value.args[-1]

	if type(resultDict) != type({}):
		resultDict = {}
		resultDict["dictId"] = u"9D6B6AA1-92FC-453E-8B9A-91D0E02A17B1"
		resultDict["stackInfo"] = traceback.extract_tb(tb)
		value.args = value.args +(resultDict, ) 

	if "dictId" not in resultDict or resultDict["dictId"] != u"9D6B6AA1-92FC-453E-8B9A-91D0E02A17B1":
		resultDict = {}
		resultDict["dictId"] = u"9D6B6AA1-92FC-453E-8B9A-91D0E02A17B1"
		resultDict["stackInfo"] = traceback.extract_tb(tb)
		value.args = value.args +(resultDict, ) 

	resultDict['stackInfo'] = revealLiterate("使用noweb对python进行文学编程.nw", thisFile, chunks, resultDict["stackInfo"])
	if '<built-in function excepthook>' == str(nextHandler):
		print 'Unhandled Exception, trace back:'
		for stackInfo in resultDict['stackInfo']:
			print ur' File "' + unicode(stackInfo[0]) + ur'", line ' + unicode(stackInfo[1]) + ur' in ' + unicode(stackInfo[2])
			print ur'   ' + unicode(stackInfo[3])
		value.args = value.args[:-1]
		print re.compile(r"<type '([^']+)'>").match(str(type)).group(1)+":", value
	elif None != nextHandler:
		nextHandler(type, value, tb)
开发者ID:qinggeng,项目名称:tools,代码行数:32,代码来源:error.py


示例13: __init__

    def __init__(self, *a, **b):
        super(ApplicationException,self).__init__(*a,**b)
        self._stacks = []

        # save current stack
        self._stack_init = traceback.extract_stack()
        self.add_stack(self.__class__.__name__ + ': ' + str(self), self._stack_init)

        # WARNING this is unreliable!  only use if cause passed as argument
        cause_info = sys.exc_info() #if retain_cause else (None,None,None)

        # add stacks and labels for cause
        if 'cause' in b:
            if isinstance(b['cause'],Application):
                self._cause = b['cause']
                cause_label = 'caused by: ' + self._cause.__class__.__name__ + ': ' + str(self._cause)
                # if ApplicationException, get stacks from its list
                if isinstance(self._cause,ApplicationException) and len(self._cause._stacks):
                    first = True
                    for label,stack in self._cause._stacks:
                        if first:
                            self.add_stack(cause_label, stack)
                            first = False
                        else:
                            self.add_stack(label, stack)
                # otherwise if this is current exception in exc_info, use its stack
                elif self._cause==cause_info[1] and cause_info[2]:
                    self._stack_cause = traceback.extract_tb(cause_info[2])
                    self.add_stack(cause_label, self._stack_cause)
            # cause is not an exception? treat as boolean, use exc_info
            elif b['cause']:
                self._cause=cause_info[1]
                if cause_info[2]:
                    self._stack_cause = traceback.extract_tb(cause_info[2])
                    self.add_stack(cause_label, self._stack_cause)
开发者ID:GrimJ,项目名称:mi-dataset,代码行数:35,代码来源:exception.py


示例14: update_sql

 def update_sql(self, line):
     sqlconpool_sem.acquire()
     #获取相关库的链接
     sqlclient,table = sqlconpool_dict.get("qita", None)
     #上传日表
     sql = "INSERT INTO "+ table+"(BW_DATE, BW_DOMAIN, BW_IP, BW_BANDWIDTH) VALUES(%s,%s,%s,%s)"
     if not sqlclient:
         self.log.error("history work sqlclient is not set %s", table)
         sqlconpool_sem.release()
         return 0
     else:
         try:
             param = line
             #插入多行
             ret = sqlclient.insertMany(sql, param)
             #事务提交
             sqlclient.end('commit')
         except:
             #发生错误, 事务回滚
             info = sys.exc_info()
             traceback.extract_tb(info[2])
             self.log.error("%s %s %s %s", info[0], info[1], sql, str(param))
             sqlconpool_sem.release()
             return 0
     sqlconpool_sem.release()
     return 1
开发者ID:net20121222,项目名称:cachetraffic,代码行数:26,代码来源:cachetraffic_historywork.py


示例15: decorator

        def decorator(*args, **kwargs):
            if not hasattr(trace, 'local'):
                trace.local = threading.local()
            tl = trace.local

            if not hasattr(tl, 'log_indent'):
                tl.log_indent = 0

            funcname = func.__module__ + "." + func.__name__

            # List all positional arguments
            margs = [str("'%s'" % arg if isinstance(arg, str) else arg) for arg in [("********" if i in redact else arg) for i, arg in enumerate(args)]]

            # List all keyword arguments
            margs.extend(["%s=%s" % (key, str("'%s'" % val if isinstance(val, str) else val)) for key, val in [(key, ("********" if key in redact else val)) for key, val in kwargs.items()]])

            try:
                logger.debug("\t" * tl.log_indent + "Entering %s(%s)" % (funcname, ", ".join(margs)))
                tl.log_indent+=1
                retval = func(*args, **kwargs)
                tl.log_indent-=1
                logger.debug("\t" * tl.log_indent + "Leaving %s = %s" % (funcname, retval))
                return retval
            except Exception as e:
                tl.log_indent -= 1
                file = traceback.extract_tb()[-1][0]
                line = traceback.extract_tb()[-1][1]
                clsfunc = e.__class__.__name__
                logger.error("\t" * tl.log_indent + "Encountered error in %s: %s(%s) [%s:%i]" % (funcname, clsfunc, e.message, file, line))
                raise e, None, exc_info()[2]
开发者ID:lamby,项目名称:django-utils,代码行数:30,代码来源:profiling.py


示例16: run_poller_worker

        def run_poller_worker(executor):
            process = multiprocessing.current_process()
            log.debug("Poller/executor %s started", process.name)
            initializer = self.initializer
            initializer(executor)
            while executor._worker_shutdown.empty():
                work_callable = None
                with poller_semaphore:

                    while work_callable is None:
                        # make sure that after we wake up we're still relevant
                        if not executor._worker_shutdown.empty():
                            return
                        try:
                            work_callable = executor._worker.poll_for_activities()
                        except Exception as err:
                            _, _, tb = sys.exc_info()
                            tb_list = traceback.extract_tb(tb)
                            handler = executor._worker.unhandled_exception_handler
                            handler(err, tb_list)

                try:
                    work_callable()
                except Exception as err:
                    _, _, tb = sys.exc_info()
                    tb_list = traceback.extract_tb(tb)
                    handler = executor._worker.unhandled_exception_handler
                    handler(err, tb_list)
开发者ID:boto,项目名称:botoflow,代码行数:28,代码来源:multiprocessing_activity_executor.py


示例17: errorCheck

def errorCheck(exception,sys):
	""" Creates a human readable error string from a system error object.
	
	Input:
		exception: an exception instance
		sys: a system error object occuring after a python exception
		
	Output:
		none: see response()
	
	"""
	try:
		error = sys.exc_info()
		errorStr = error[1][0]
		errorLine = traceback.extract_tb(error[2])[0][1]
		errorType = error[0]
		errorFile = traceback.extract_tb(error[2])[0][0]
		errorMod = traceback.extract_tb(error[2])[0][2]
		try:
			trace = traceback.extract_tb(error[2])[1]
			errorOut = str(errorType)+' ERROR IN '+errorFile+'/'+ errorMod+' AT LINE '+str(errorLine)+':: ERROR: '+errorStr + '  | TRACEBACK: ' + trace[0] + ' LINE ' + str(trace[1])
		except:
			errorOut = str(errorType)+' ERROR IN '+errorFile+'/'+ errorMod+' AT LINE '+str(errorLine)+':: ERROR: '+errorStr
		
		return response(0, ujson.dumps(errorOut),{})
	except:
		try: 
			#If error check fails, try to return some useful info. 
			return response(0, str(exception),{})
		except:
			return response(0, 'ERROR: ERROR CHECK FAILED ON EXCEPTION.',{})
开发者ID:CReSIS,项目名称:OPS,代码行数:31,代码来源:utility.py


示例18: _calculate

def _calculate(worksheet, usercode, private_key):
    worksheet.clear_values()
    worksheet._console_text = ''
    worksheet._usercode_error = None

    context = {
        'worksheet': worksheet,
        'load_constants': load_constants,
        'undefined': undefined,

        'CellRange': CellRange,
        'DateTime': DateTime,
        'FormulaError': FormulaError,
        '_raise': _raise,
        'sys': sys,
    }
    context['run_worksheet'] = lambda url, overrides=None: run_worksheet(url, overrides, private_key)
    context['evaluate_formulae'] = lambda worksheet: evaluate_formulae_in_context(worksheet, context)
    sys.stdout = MyStdout(worksheet)

    try:
        execute_usercode(usercode, context)
    except Exception, e:
        if isinstance(e, SyntaxError):
            error = 'Syntax error at character %d' % (e.offset,)
            line_no = e.lineno
            worksheet.add_console_text("%s (line %s)\n" % (error, line_no))
        else:
            error = "%s: %s" % (type(e).__name__, str(e))
            tb = sys.exc_info()[2]
            line_no = traceback.extract_tb(tb)[-1][1]
            worksheet.add_console_text("%s\n%s\n" % (error, format_traceback(traceback.extract_tb(tb))))
        worksheet._usercode_error = {"message": error, "line": line_no}
开发者ID:bwhmather,项目名称:dirigible-spreadsheet,代码行数:33,代码来源:calculate.py


示例19: test_traceback_stack

    def test_traceback_stack(self):
        import sys
        import traceback

        def C():
            raise Exception

        def B():
            C()

        def A():
            try:
                B()
            except:
                return sys.exc_info()[2]

        lineno = C.func_code.co_firstlineno
        tb = A()

        a = traceback.extract_tb(tb)
        b = traceback.extract_stack(tb.tb_frame, 1)
        self.assertEqual(a, [(__file__, 8+lineno, 'A', 'B()'), (__file__, 4+lineno, 'B', 'C()'), (__file__, 1+lineno, 'C', 'raise Exception')])
        self.assertEqual([x[2] for x in b], ['A']) # only check that we're in the proper function, the rest does not work properly

        tb = tb.tb_next
        a = traceback.extract_tb(tb)
        b = traceback.extract_stack(tb.tb_frame, 2)
        self.assertEqual(a, [(__file__, 4+lineno, 'B', 'C()'), (__file__, 1+lineno, 'C', 'raise Exception')])
        self.assertEqual([x[2] for x in b], ['A', 'B']) # only check that we're in the proper function, the rest does not work properly

        tb = tb.tb_next
        a = traceback.extract_tb(tb)
        b = traceback.extract_stack(tb.tb_frame, 3)
        self.assertEqual(a, [(__file__, 1+lineno, 'C', 'raise Exception')])
        self.assertEqual([x[2] for x in b], ['A', 'B', 'C']) # only check that we're in the proper function, the rest does not work properly
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:35,代码来源:test_regressions.py


示例20: traceback_info

    def traceback_info(self, last_traceback):
        """
        Extracts the informations from the traceback.

        Add the keys ``filename`` and ``line`` pointing to the root
        of the exception.
        Also adds the key ``traceback`` containing a dump of the traceback
        as a :class:`list`.
        """
        all_tb = [dict(zip(('filename', 'line', 'in', 'call'), x))
                  for x in traceback.extract_tb(last_traceback)]
        for i, frame in enumerate(all_tb):
            if not frame['filename'].startswith(self.napix_path):
                break
        else:
            i = 0

        all_tb = all_tb[i:]
        filename, lineno, function_name, text = traceback.extract_tb(
            last_traceback)[-1]

        return {
            'traceback': all_tb,
            'filename': filename,
            'line': lineno,
        }
开发者ID:eNiXHosting,项目名称:NapixServer,代码行数:26,代码来源:exceptions.py



注:本文中的traceback.extract_tb函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python traceback.format_exc函数代码示例发布时间:2022-05-27
下一篇:
Python traceback.extract_stack函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap