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

Python traceback.format_stack函数代码示例

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

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



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

示例1: _ensure_transport

    def _ensure_transport(self):
        """
        Ensures this Channel has been activated with the Node.
        """
#        log.debug("BaseChannel._ensure_transport (current: %s)", self._transport is not None)
        if not self._transport:
            raise ChannelError("No transport attached")

        if not self._lock:
            raise ChannelError("No lock available")

        # is lock already acquired? spit out a notice
        if self._lock._is_owned():
            log.warn("INTERLEAVE DETECTED:\n\nCURRENT STACK:\n%s\n\nSTACK THAT LOCKED: %s\n",
                    "".join(traceback.format_stack()), "".join(self._lock_trace))

        with self._lock:
            # we could wait and wait, and it gets closed, and unless we check again, we'd never know!
            if not self._transport:
                raise ChannelError("No transport attached")

            self._lock_trace = traceback.format_stack()
            try:
                yield
            finally:
                self._lock_trace = None
开发者ID:mkl-,项目名称:scioncc,代码行数:26,代码来源:channel.py


示例2: _submit

def _submit(runConfig):
    if registry.has_run(runConfig.runid):
        msg = "Runid %s does already exist" % runConfig.runid
        return SubmissionResponse(runConfig.runid, SUBM_ALREADY_SUBMITTED, msg)
        
    try:
        pipeline_exec = PipelineExecution(runConfig, server_model.config)
        logger.debug("PipelineExecution object for runid %s created."%runConfig.runid)
        pipeline_exec.initialize()
        logger.debug("PipelineExecution object for runid %s initialized."%runConfig.runid)
        registry.add_run(runConfig.runid, pipeline_exec)
        logger.debug("PipelineExecution object for runid %s registered."%runConfig.runid)
        _ = pipeline_exec.start()
        msg = "Pipeline execution for runid %s started."%runConfig.runid
        logger.info(msg)
    except ConfigurationError as ce:
        msg = 'Submission failed with exception %s.' % str(ce)
        stacktrace= 'Stacktrace: \n%s'%'\n'.join(traceback.format_stack())
        logger.warn(msg)
        return SubmissionResponse(runConfig.runid, SUBM_FAILED, msg, stacktrace)
    except Exception as e:
        msg = 'Submission failed with exception %s.' % str(e)
        stacktrace= 'Stacktrace: \n%s'%'\n'.join(traceback.format_stack())
        logger.error(msg)
        return SubmissionResponse(runConfig.runid, SUBM_ERROR, msg, stacktrace)
    try:
        history.add_entry("Runid %s submitted to the system" % runConfig.runid, datetime.datetime.now())
    except Exception as e:
        logger.warn("Runid %s could not be appended to the history."%runConfig.runid)
        msg=msg+"\n But not entry could be added the server history."

    return SubmissionResponse(runConfig.runid, SUBM_EXECUTING, msg)
开发者ID:istoney,项目名称:eucliddatasimulator,代码行数:32,代码来源:server_views_flask.py


示例3: queuedb_query_execute

def queuedb_query_execute( cur, query, values ):
    """
    Execute a query.  If it fails, exit.

    DO NOT CALL THIS DIRECTLY.
    """
    timeout = 1.0
    while True:
        try:
            ret = cur.execute( query, values )
            return ret
        except sqlite3.OperationalError as oe:
            if oe.message == "database is locked":
                timeout = timeout * 2 + timeout * random.random()
                log.error("Query timed out due to lock; retrying in %s: %s" % (timeout, namedb_format_query( query, values )))
                time.sleep(timeout)
            
            else:
                log.exception(oe)
                log.error("FATAL: failed to execute query (%s, %s)" % (query, values))
                log.error("\n".join(traceback.format_stack()))
                os.abort()

        except Exception, e:
            log.exception(e)
            log.error("FATAL: failed to execute query (%s, %s)" % (query, values))
            log.error("\n".join(traceback.format_stack()))
            os.abort()
开发者ID:destenson,项目名称:blockstack--blockstack-server,代码行数:28,代码来源:queue.py


示例4: deprecated

	def deprecated(self, method):
		"""Output a deprecation warning.

		The implementation of WebKit sometimes invokes this method which prints
		a warning that the method you are using has been deprecated.
		This method expects that deprecated methods say so at the beginning of
		their doc string and terminate that msg with @. For example:

			DEPRECATED: Class.foo() on 01/24/01 in ver 0.5. Use Class.bar() instead. @

		Putting this information in the doc string is important for accuracy
		in the generated docs.

		Example call:
			self.deprecated(self.foo)

		"""
		docString = method.__doc__
		if docString:
			msg = docString.split('@')[0]
			msg = '\n'.join(map(lambda s: s.strip(), msg.splitlines()))
		else:
			msg = 'DEPRECATED: %s (no doc string)' % method
		print msg
		try:
			from traceback import format_stack
			print format_stack(limit =3)[0]
		except Exception:
			print 'Could not determine calling function.'
开发者ID:akkmzack,项目名称:RIOS-8.5,代码行数:29,代码来源:Object.py


示例5: __init__

    def __init__(self, *args, **kwargs):
        if len(args) == 1 and not kwargs and isinstance(args[0], Exception):
            # we shall just wrap a non-caused exception
            self.stack = traceback.format_stack()[:-2] + traceback.format_tb(sys.exc_info()[2])
            # ^^^ let's hope the information is still there; caller must take
            #     care of this.
            self.wrapped = args[0]
            self.cause = ()
            super(CausedException, self).__init__(repr(args[0]))
            # ^^^ to display what it is wrapping, in case it gets printed or similar
            return

        self.wrapped = None
        # cut off frames we don't care about
        class_depth = max(ancestor_class_depth(CausedException, self.__class__), 0)
        self.stack = traceback.format_stack()[: -(class_depth + 1)]

        try:
            cause = kwargs["cause"]
            del kwargs["cause"]
        except:
            cause = ()

        if isinstance(cause, Exception) and not isinstance(cause, CausedException):
            cause = CausedException(cause)
        self.cause = cause if isinstance(cause, tuple) else (cause,)
        super(CausedException, self).__init__(*args, **kwargs)
开发者ID:roguenet,项目名称:microtome,代码行数:27,代码来源:error.py


示例6: trace

 def trace(self, output=''):
     if output == 'stderr':
         sys.stderr.write(''.join(traceback.format_stack()))
         sys.stderr.flush()
     else:
         sys.stdout.write(''.join(traceback.format_stack()))
         sys.stdout.flush()
开发者ID:joaduo,项目名称:mepinta2,代码行数:7,代码来源:Logger.py


示例7: entryExitLoggingWrap

    def entryExitLoggingWrap(*args, **kwargs):

      if entryExitLogLevel is None:
        enabled = False
      else:
        logger = getLoggerCallback()
        enabled = logger.isEnabledFor(entryExitLogLevel)

      if not enabled:
        return func(*args, **kwargs)
      
      funcName = str(func)
      
      if logArgs:
        argsRepr = ', '.join(
          [repr(a) for a in args] +
          ['%s=%r' % (k,v,) for k,v in kwargs.iteritems()])
      else:
        argsRepr = ''
      
      logger.log(
        entryExitLogLevel, "ENTERING: %s(%s)%s", funcName, argsRepr,
        '' if not logTraceback else '; ' + repr(traceback.format_stack()))

      try:
        return func(*args, **kwargs)
      finally:
        logger.log(
          entryExitLogLevel, "LEAVING: %s(%s)%s", funcName, argsRepr,
          '' if not logTraceback else '; ' + repr(traceback.format_stack()))
开发者ID:akhilaananthram,项目名称:nupic,代码行数:30,代码来源:decorators.py


示例8: error

def error(event, raises=False, e_type=Exception, log_trace=True, limit=None):
    """A level of information that may have caused an error.

    :param event: error event instance
    :param raises: boolean of whether or not an error should be raised
    :param e_type: exception type to be raised
    :param log_trace: boolean of whether or not log traceback
    :param limit: integer of traceback limit
    """
    if raises:
        if hasattr(event, "info"):
            logged_exception = e_type(event.info)
        else:
            logged_exception = e_type(event)

        if log_trace:
            try:
                raise logged_exception
            except Exception as err:
                given_traceback = traceback.format_stack(limit=limit)[:-1]
                given_traceback.append(traceback.format_exc(limit=limit))
                event.info += '\n' + ''.join(given_traceback)
            finally:
                raise logged_exception
        else:
            raise logged_exception

    elif log_trace:
        event.info += ''.join(traceback.format_stack())
开发者ID:GreenVars,项目名称:diary,代码行数:29,代码来源:levels.py


示例9: endrun

 def endrun(self, status):
     """By convention for now, status is one of:
         'DEAD'
         'UNSUBMITTED' (a pseudo-status defined in the ready-loop of alive())
         'EXIT rc'
     """
     name = status.split()[0]
     if name == 'DEAD':
         log.warning(''.join(traceback.format_stack()))
         log.error('Task {}\n is DEAD, meaning no HEARTBEAT, but this can be a race-condition. If it was not killed, then restarting might suffice. Otherwise, you might have excessive clock-skew.'.format(self.brief()))
         self.setTargetStatus(pypeflow.task.TaskFail) # for lack of anything better
     elif name == 'UNSUBMITTED':
         log.warning(''.join(traceback.format_stack()))
         log.error('Task {}\n is UNSUBMITTED, meaning job-submission somehow failed. Possibly a re-start would work. Otherwise, you need to investigate.'.format(self.brief()))
         self.setTargetStatus(pypeflow.task.TaskFail) # for lack of anything better
     elif name != 'EXIT':
         raise Exception('Unexpected status {!r}'.format(name))
     else:
         code = int(status.split()[1])
         if 0 == code:
             self.__target.check_missing()
             # TODO: If missing, just leave the status as TaskInitialized?
         else:
             log.error('Task {} failed with exit-code={}'.format(self.brief(), code))
             self.setTargetStatus(pypeflow.task.TaskFail) # for lack of anything better
     self.__target.finish()
开发者ID:lindechun,项目名称:pypeFLOW,代码行数:26,代码来源:pwatcher_bridge.py


示例10: __formatFailure

  def __formatFailure(self, failure, logMessage, extras):
    """Generates a dict from the given Failure object."""

    parts = ['Traceback (most recent call last):']
    if not failure.frames:
      parts += traceback.format_stack()
    else:
      for functionName, filename, lineNumber, _, _ in failure.frames:
        parts.append('File "%s", line %s, in %s' % (filename, lineNumber, functionName))
    backtrace = '\n'.join(parts)

    result = {
      'project': self.__project,
      'type': failure.type.__module__ + '.' + failure.type.__name__,
      'message': str(failure.value),
      'environment': self.__environment,
      'serverName': self.__serverName,
      'logMessage': logMessage,
      'backtrace': backtrace,
      'loggedFrom': '\n'.join(traceback.format_stack())
    }

    if extras and 'level' in extras:
      result['errorLevel'] = extras['level']
      del extras['level']

    if context and context.all():
      result['context'] = context.all()
      if extras:
        result['context'] = result['context'].copy()
        result['context'].update(extras)
    elif extras:
      result['context'] = extras

    return result
开发者ID:Cue,项目名称:greplin-exception-catcher,代码行数:35,代码来源:twistedLog.py


示例11: upsert

    def upsert(self, pgUrl, commit=True, **kwargs):
        if "url" in kwargs and "drive_web" in kwargs["url"]:
            self.log.error("")
            self.log.error("")
            self.log.error("WAT")
            self.log.error("")
            self.log.error(traceback.format_stack())
            self.log.error("")

        if "url" in kwargs and not kwargs["url"].startswith("http"):
            self.log.error("")
            self.log.error("")
            self.log.error("WAT")
            self.log.error("")
            self.log.error(traceback.format_stack())
            self.log.error("")

            # print("Upserting!")

        with self.transaction(commit=commit) as cur:
            # Do everything in one transaction

            try:
                self.insertIntoDb(url=pgUrl, cursor=cur, **kwargs)

            except psycopg2.IntegrityError:
                if kwargs:
                    cur.execute("ROLLBACK")
                    cur.execute("BEGIN")
                    self.updateDbEntry(url=pgUrl, cursor=cur, **kwargs)
开发者ID:asl97,项目名称:MangaCMS,代码行数:30,代码来源:TextDbBase.py


示例12: drop_transaction

    def drop_transaction(self, transaction):
        """Drops the specified transaction, validating that it is
        actually saved away under the current executing thread.

        """

        thread_id = transaction.thread_id

        if not thread_id in self._cache:
            _logger.error('Runtime instrumentation error. Attempt to '
                    'to drop the transaction but where none is active. '
                    'Report this issue to New Relic support.\n%s',
                    ''.join(traceback.format_stack()[:-1]))

            raise RuntimeError('no active transaction')

        current = self._cache.get(thread_id)

        if transaction != current:
            _logger.error('Runtime instrumentation error. Attempt to '
                    'to drop the transaction when it is not the current '
                    'transaction. Report this issue to New Relic support.\n%s',
                    ''.join(traceback.format_stack()[:-1]))

            raise RuntimeError('not the current transaction')

        transaction._greenlet = None

        del self._cache[thread_id]
开发者ID:bobbyrward,项目名称:newrelic,代码行数:29,代码来源:transaction_cache.py


示例13: checkExceptionPerGreenlet

def checkExceptionPerGreenlet(outfileName=None, ignoreHealthyOnes=True):
    mylog("Trying to detect greenlets...", verboseLevel=-2)
    if not outfileName:
        for ob in gc.get_objects():
            if not hasattr(ob, 'parent_args'):
                continue
            if not ob:
                continue
            if ignoreHealthyOnes and (not ob.exception):
                 continue
            mylog('%s[%s] called with parent arg\n(%s)\n%s' % (ob.name, repr(ob.args), repr(ob.parent_args),
                ''.join(traceback.format_stack(ob.gr_frame))), verboseLevel=-2)
            mylog(ob.exception, verboseLevel=-2)
    else:
        handler = open(outfileName, 'w')
        for ob in gc.get_objects():
            if not hasattr(ob, 'parent_args'):
                continue
            if not ob:
                continue
            if ignoreHealthyOnes and (not ob.exception):
                 continue
            handler.write('%s[%s] called with parent arg\n(%s)\n%s' % (ob.name, repr(ob.args), repr(ob.parent_args),
                ''.join(traceback.format_stack(ob.gr_frame))))
            handler.write(ob.exception)
开发者ID:amiller,项目名称:HoneyBadgerBFT,代码行数:25,代码来源:utils.py


示例14: __init__

 def __init__(self, *args, **kwargs):
     if len(args) == 1 and not kwargs and isinstance(args[0], Exception):
         # we shall just wrap a non-caused exception
         self.stack = (
             traceback.format_stack()[:-2] +
             traceback.format_tb(sys.exc_info()[2]))
         # ^^^ let's hope the information is still there; caller must take
         # care of this.
         self.wrapped = args[0]
         self._cause = []
         super(CausedException, self).__init__(repr(args[0]))
         # ^^^ to display what it is wrapping, in case it gets printed or similar
         return
     self.wrapped = None
     self.stack = traceback.format_stack()[:-1]  # cut off current frame
     try:
         cause = kwargs['cause']
         del kwargs['cause']
     except KeyError:
         cause = []
     if not isinstance(cause, list):
         cause = [cause]
     self._cause = [CausedException(e) if not isinstance(e, CausedException) else e for e in cause]
     self.kwargs = kwargs
     super(CausedException, self).__init__(*args)
开发者ID:Bolisov,项目名称:plugin.video.lostfilm.tv,代码行数:25,代码来源:causedexception.py


示例15: dump_stacks

def dump_stacks():
    dump = []

    # threads
    threads = dict([(th.ident, th.name)
                    for th in threading.enumerate()])

    for thread, frame in sys._current_frames().items():
        if thread not in threads:
            continue
        dump.append('Thread 0x%x (%s)\n' % (thread, threads[thread]))
        dump.append(''.join(traceback.format_stack(frame)))
        dump.append('\n')

    # greenlets
    try:
        from greenlet import greenlet
    except ImportError:
        return dump

    # if greenlet is present, let's dump each greenlet stack
    for ob in gc.get_objects():
        if not isinstance(ob, greenlet):
            continue
        if not ob:
            continue   # not running anymore or not started
        dump.append('Greenlet\n')
        dump.append(''.join(traceback.format_stack(ob.gr_frame)))
        dump.append('\n')

    return dump
开发者ID:jether2011,项目名称:loads,代码行数:31,代码来源:util.py


示例16: updateObject

	def updateObject(self, table_name, flt, values, turn_n = None):
		#table_name = '%s_%s'%(table, turn_n) if turn_n else table
		try:
			self.cur.execute('update %s SET %s WHERE %s'%(table_name, ','.join(['%s=%s'%(k,v) for k,v in values.iteritems()]), ' AND '.join(flt)))
			self.conn.commit()
		except sqlite3.Error, e:
			log.error('Error "%s", when executing: delete from %s WHERE %s'%(e, table_name, ' AND '.join(data)))
			print traceback.format_stack()		
开发者ID:bogolt,项目名称:dclord,代码行数:8,代码来源:db.py


示例17: eraseObject

	def eraseObject(self, table_name, data, turn_n = None):
		#table_name = '%s_%s'%(table, turn_n) if turn_n else table
		try:
			self.cur.execute('delete from %s WHERE %s'%(table_name, ' AND '.join(data)))
			self.conn.commit()
		except sqlite3.Error, e:
			log.error('Error "%s", when executing: delete from %s WHERE %s'%(e, table_name, ' AND '.join(data)))
			print traceback.format_stack()
开发者ID:bogolt,项目名称:dclord,代码行数:8,代码来源:db.py


示例18: printTrace

 def printTrace(self, output=''):
     if output == 'stderr':
         sys.stderr.write(''.join(traceback.format_stack()))
         if self.__log_level >= self.__levels['debug']:
             sys.stderr.flush()
     else:
         sys.stdout.write(''.join(traceback.format_stack()))
         if self.__log_level >= self.__levels['debug']:
             sys.stdout.flush()
开发者ID:joaduo,项目名称:mepinta2,代码行数:9,代码来源:Logger.py


示例19: timeout

				def timeout(self):
					try:
						import time

						now = time.strftime('%c')
						self.journal.info("## %s: %s ##" % (now, self.message))
					except:
						import traceback
						traceback.format_stack()
开发者ID:okirch,项目名称:susetest,代码行数:9,代码来源:twopence-ctcs2.py


示例20: prlk_stack

def prlk_stack(siPrevio=False):
    import traceback

    if siPrevio:
        prlk("-" * 80 + "\n")
        prlk(traceback.format_stack())
        prlk("\n" + "-" * 80 + "\n")
    for line in traceback.format_stack()[:-1]:
        prlk(line.strip() + "\n")
开发者ID:JERUKA9,项目名称:lucaschess,代码行数:9,代码来源:Constantes.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python traceback.format_tb函数代码示例发布时间:2022-05-27
下一篇:
Python traceback.format_list函数代码示例发布时间: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