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

Python sys._exc_info函数代码示例

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

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



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

示例1: run

    def run(self, sleep=0, mode=None, log=True, __self=None):
        if __self is not None:
            self = __self

        if not mode == "T":
            if os.name == "posix":
                signal(SIGHUP, self._signal)
            signal(SIGINT, self._signal)
            signal(SIGTERM, self._signal)

        self._running = True

        self.push(Started(self, mode))

        try:
            while self.running:
                try:
                    [f() for f in self._ticks.copy()]
                    self._flush()
                    if sleep:
                        try:
                            time.sleep(sleep)
                        except:
                            pass
                except (KeyboardInterrupt, SystemExit):
                    self._running = False
                except:
                    try:
                        if log:
                            self.push(Error(*_exc_info()))
                    finally:
                        self._flush()
        finally:
            try:
                self.push(Stopped(self))
                rtime = time.time()
                while len(self) > 0 and (time.time() - rtime) < 3:
                    try:
                        [f() for f in self._ticks.copy()]
                        self._flush()
                        if sleep:
                            time.sleep(sleep)
                        rtime = time.time()
                    except:
                        try:
                            if log:
                                self.push(Error(*_exc_info()))
                        finally:
                            self._flush()
            except:
                pass
开发者ID:bluemoon,项目名称:hestia,代码行数:51,代码来源:event_driven.py


示例2: get_error_page

def get_error_page(status, **kwargs):
    """Return an HTML page, containing a pretty error response.

    status should be an int or a str.
    kwargs will be interpolated into the page template.
    """
    import cherrypy

    try:
        code, reason, message = _httputil.valid_status(status)
    except ValueError:
        raise cherrypy.HTTPError(500, _exc_info()[1].args[0])

    # We can't use setdefault here, because some
    # callers send None for kwarg values.
    if kwargs.get('status') is None:
        kwargs['status'] = "%s %s" % (code, reason)
    if kwargs.get('message') is None:
        kwargs['message'] = message
    if kwargs.get('traceback') is None:
        kwargs['traceback'] = ''
    if kwargs.get('version') is None:
        kwargs['version'] = cherrypy.__version__

    for k, v in iteritems(kwargs):
        if v is None:
            kwargs[k] = ""
        else:
            kwargs[k] = _escape(kwargs[k])

    # Use a custom template or callable for the error page?
    pages = cherrypy.serving.request.error_page
    error_page = pages.get(code) or pages.get('default')
    if error_page:
        try:
            if hasattr(error_page, '__call__'):
                return error_page(**kwargs)
            else:
                data = open(error_page, 'rb').read()
                return tonative(data) % kwargs
        except:
            e = _format_exception(*_exc_info())[-1]
            m = kwargs['message']
            if m:
                m += "<br />"
            m += "In addition, the custom error page failed:\n<br />%s" % e
            kwargs['message'] = m

    return _HTTPErrorTemplate % kwargs
开发者ID:ducin,项目名称:cherrypy,代码行数:49,代码来源:_cperror.py


示例3: format_exc

def format_exc(exc = None):
    if exc is None:
        exc = _exc_info()
    if exc == (None, None, None):
        return ''
    import traceback
    return ''.join(traceback.format_exception(*exc))
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:7,代码来源:_cperror.py


示例4: unexpected_json_error_handler

def unexpected_json_error_handler():
    """request.error_response"""

    (typ, value, tb) = _exc_info()
    if typ:
        debug = False
        if hasattr(cherrypy.request, 'params'):
            params = cherrypy.request.params
            debug = 'debug' in params and params['debug']

        response = cherrypy.response
        response.headers['Content-Type'] = 'application/json'
        response.headers.pop('Content-Length', None)
        content = {}
        if isinstance(value, ExtendedHTTPError):
            content.update({'errors': value.errors})
        if isinstance(typ, cherrypy.HTTPError):
            cherrypy._cperror.clean_headers(value.code)
            response.status = value.status
            content.update({'code': value.code, 'reason': value.reason,
                            'message': value._message})
        elif isinstance(typ, (TypeError, ValueError, KeyError)):
            cherrypy._cperror.clean_headers(400)
            response.status = 400
            reason, default_message = _httputil.response_codes[400]
            content = {'code': 400, 'reason': reason,
                       'message': value.message or default_message}

        if cherrypy.serving.request.show_tracebacks or debug:
            tb = _format_exc()
            content['traceback'] = tb
        response.body = json.dumps(content).encode('utf-8')
开发者ID:GDG-Ukraine,项目名称:gdg.org.ua,代码行数:32,代码来源:errors.py


示例5: _send

    def _send(self, event, channel, errors=False, log=True):
        eargs = event.args
        ekwargs = event.kwargs

        r = False
        for handler in self._getHandlers(channel):
            try:
                #stime = time.time()
                if handler._passEvent:
                    r = handler(event, *eargs, **ekwargs)
                else:
                    r = handler(*eargs, **ekwargs)
                #etime = time.time()
                #ttime = (etime - stime) * 1e3
                #print "%s: %0.02f ms" % (reprhandler(handler), ttime)
            except (KeyboardInterrupt, SystemExit):
                raise
            except:
                if log:
                    etype, evalue, etraceback = _exc_info()
                    self.push(Error(etype, evalue, etraceback, handler=handler))
                if errors:
                    raise
                else:
                    _exc_clear()
            if r is not None and r and handler.filter:
                return r
        return r
开发者ID:bluemoon,项目名称:hestia,代码行数:28,代码来源:event_driven.py


示例6: format_exc

def format_exc(exc=None):
    """Return exc (or sys.exc_info if None), formatted."""
    if exc is None:
        exc = _exc_info()
    if exc == (None, None, None):
        return ""
    import traceback
    return "".join(traceback.format_exception(*exc))
开发者ID:070499,项目名称:Sick-Beard,代码行数:8,代码来源:_cperror.py


示例7: tick

 def tick(self):
     if self._ticks:
         try:
             [f() for f in self._ticks.copy()]
         except:
             etype, evalue, etraceback = _exc_info()
             self.fire(Error(etype, evalue, format_tb(etraceback)))
     if self:
         self._flush()
开发者ID:AlphaStaxLLC,项目名称:TundraAddons,代码行数:9,代码来源:manager.py


示例8: format_exc

def format_exc(exc=None):
    """Return exc (or sys.exc_info if None), formatted."""
    try:
        if exc is None:
            exc = _exc_info()
        if exc == (None, None, None):
            return ''
        import traceback
        return ''.join(traceback.format_exception(*exc))
    finally:
        del exc
开发者ID:coady,项目名称:cherrypy,代码行数:11,代码来源:_cperror.py


示例9: _on_request

    def _on_request(self, event, req, res):
        if not self.apps:
            return

        parts = req.path.split("/")

        candidates = []
        for i in range(len(parts)):
            k = "/".join(parts[:(i + 1)]) or "/"
            if k in self.apps:
                candidates.append((k, self.apps[k]))
        candidates = sorted(candidates, key=itemgetter(0), reverse=True)

        if not candidates:
            return

        path, app = candidates[0]

        buffer = StringIO()

        def start_response(status, headers, exc_info=None):
            res.status = int(status.split(" ", 1)[0])
            for header in headers:
                res.headers.add_header(*header)
            return buffer.write

        errors = self.errors[path]

        environ = create_environ(errors, path, req)

        try:
            body = app(environ, start_response)
            if isinstance(body, list):
                _body = type(body[0])() if body else ""
                body = _body.join(body)
            elif isinstance(body, GeneratorType):
                res.body = body
                res.stream = True
                return res

            if not body:
                if not buffer.tell():
                    return empty
                else:
                    buffer.seek(0)
                    return buffer
            else:
                return body
        except Exception as error:
            etype, evalue, etraceback = _exc_info()
            error = (etype, evalue, format_tb(etraceback))
            return httperror(req, res, 500, error=error)
        finally:
            event.stop()
开发者ID:spaceone,项目名称:circuits,代码行数:54,代码来源:wsgi.py


示例10: get_traceback_string

def get_traceback_string():
    """
    Gibt den Traceback-String des letzten Fehlers zurück
    """

    from sys import exc_info as _exc_info
    exc = _exc_info()
    if exc == (None, None, None):
        return ""
    import traceback
    tb = "".join(traceback.format_exception(*exc))

    # Fertig
    return tb
开发者ID:gerold-penz,项目名称:gae-address-book,代码行数:14,代码来源:format_.py


示例11: _on_request

    def _on_request(self, event, request, response):
        if self.path and not request.path.startswith(self.path):
            return

        req = event
        path = request.path

        if self.path is not None:
            path = path[len(self.path):]
            req.path = path

        self._request = request
        self._response = response

        try:
            return self.app(self.createEnviron(), self.start_response)
        except Exception, error:
            status = 500
            message = str(error)
            error = _exc_info()
            etype, evalue, etraceback = _exc_info()
            error = (etype, evalue, format_tb(etraceback))
            return HTTPError(request, response, status, message, error)
开发者ID:A-K,项目名称:naali,代码行数:23,代码来源:wsgi.py


示例12: get_traceback_string

def get_traceback_string():
    """
    Returns the traceback unicode string for the last error
    """

    from sys import exc_info as _exc_info
    exc = _exc_info()
    if exc == (None, None, None):
        return ""
    import traceback
    tb = "".join(traceback.format_exception(*exc))

    # Fertig
    return unicode(tb, errors = "replace")
开发者ID:gerold-penz,项目名称:python-jsonrpc,代码行数:14,代码来源:rpcerror.py


示例13: __init__

    def __init__(self, status=500, message=None):
        self.status = status
        try:
            self.code, self.reason, defaultmsg = _httputil.valid_status(status)
        except ValueError:
            raise self.__class__(500, _exc_info()[1].args[0])

        if self.code < 400 or self.code > 599:
            raise ValueError("status must be between 400 and 599.")

        # See http://www.python.org/dev/peps/pep-0352/
        # self.message = message
        self._message = message or defaultmsg
        CherryPyException.__init__(self, status, message)
开发者ID:ducin,项目名称:cherrypy,代码行数:14,代码来源:_cperror.py


示例14: run

    def run(self, sleep=0, mode=None, errors=False, log=True, __self=None):
        if __self is not None:
            self = __self

        if not mode == "T":
            #signal(SIGHUP, self._signal)
            signal(SIGINT, self._signal)
            signal(SIGTERM, self._signal)

        self._running = True

        self.push(Started(self, mode), "started")

        try:
            while self._running:
                try:
                    [f() for f in self.ticks.copy()]
                    self.flush()
                    if sleep:
                        try:
                            time.sleep(sleep)
                        except:
                            pass
                except (KeyboardInterrupt, SystemExit):
                    self._running = False
                except:
                    try:
                        if log:
                            self.push(Error(*_exc_info()), "error")
                        if errors:
                            raise
                        else:
                            _exc_clear()
                    except:
                        pass
        finally:
            try:
                self.push(Stopped(self), "stopped")
                rtime = time.time()
                while len(self) > 0 and (time.time() - rtime) < 3:
                    [f() for f in self.ticks.copy()]
                    self.flush()
                    if sleep:
                        time.sleep(sleep)
                    rtime = time.time()
            except:
                pass
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:47,代码来源:core.py


示例15: handle_error

def handle_error():
    """
    Note:
        Not catch Httpd code 3XX~4XX exception. These exception will just response to client. 
    """
    excpetion_inst = _exc_info()[1]

    if isinstance(excpetion_inst, RequestError):
        cherrypy.response.headers['Content-Type'] = 'application/json'
        cherrypy.response.status = excpetion_inst.http_status
        resp = Response(success=False, err_code=excpetion_inst.code, err_msg=excpetion_inst.get_msg())
        cherrypy.response.body = json.dumps(resp)
    else:  # hide exception information
        cherrypy.response.show_tracebacks = False
        cherrypy.response.status = 500
        cherrypy.response.body = [
            "<html><body>%s</body></html>" % ERR_MSG[500]
        ]
开发者ID:codeguycool,项目名称:CEC,代码行数:18,代码来源:main.py


示例16: _send

    def _send(self, event, channel, errors=False, log=True):
        eargs = event.args
        ekwargs = event.kwargs

        if event.start is not None:
            self.push(Start(event), *event.start)

        retval = None
        handler = None

        for handler in self._getHandlers(channel):
            event.handler = handler
            if event.before is not None:
                self.push(Before(event, handler), *event.before)
            try:
                if handler._passEvent:
                    retval = handler(event, *eargs, **ekwargs)
                else:
                    retval = handler(*eargs, **ekwargs)
            except (KeyboardInterrupt, SystemExit):
                raise
            except:
                etype, evalue, etraceback = _exc_info()
                if event.failure is not None:
                    error = (etype, evalue, etraceback)
                    self.push(Failure(event, handler, error), *event.failure)
                if log:
                    self.push(Error(etype, evalue, etraceback, handler=handler))
                if errors:
                    raise

            if retval is not None and retval and handler.filter:
                if event.filter is not None:
                    self.push(Filter(event, handler, retval), *event.filter)
                return retval

            if event.success is not None:
                self.push(Success(event, handler, retval), *event.success)

        if event.end is not None:
            self.push(End(event, handler, retval), *event.end)

        return retval
开发者ID:Belsepubi,项目名称:naali,代码行数:43,代码来源:__init__.py


示例17: request

    def request(self, event, request, response):
        if self.path is not None and not request.path.startswith(self.path):
            return

        req = event
        path = request.path

        if self.path is not None:
            path = path[len(self.path):]
            req.path = path

        self._request = request
        self._response = response

        try:
            return "".join(self.app(self._createEnviron(), self.start_response))
        except Exception, error:
            status = error.code
            message = error.message
            error = _exc_info()
            return HTTPError(request, response, status, message, error)
开发者ID:Belsepubi,项目名称:naali,代码行数:21,代码来源:wsgi.py


示例18: get_error_page

def get_error_page(status, **kwargs):
    import cherrypy
    try:
        code, reason, message = _httputil.valid_status(status)
    except ValueError as x:
        raise cherrypy.HTTPError(500, x.args[0])

    if kwargs.get('status') is None:
        kwargs['status'] = '%s %s' % (code, reason)
    if kwargs.get('message') is None:
        kwargs['message'] = message
    if kwargs.get('traceback') is None:
        kwargs['traceback'] = ''
    if kwargs.get('version') is None:
        kwargs['version'] = cherrypy.__version__
    for k, v in iteritems(kwargs):
        if v is None:
            kwargs[k] = ''
        else:
            kwargs[k] = _escape(kwargs[k])

    pages = cherrypy.serving.request.error_page
    error_page = pages.get(code) or pages.get('default')
    if error_page:
        try:
            if hasattr(error_page, '__call__'):
                return error_page(**kwargs)
            return open(error_page, 'rb').read() % kwargs
        except:
            e = _format_exception(*_exc_info())[-1]
            m = kwargs['message']
            if m:
                m += '<br />'
            m += 'In addition, the custom error page failed:\n<br />%s' % e
            kwargs['message'] = m

    return _HTTPErrorTemplate % kwargs
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:37,代码来源:_cperror.py


示例19: __handleEvent

    def __handleEvent(self, event, channel):
        eargs = event.args
        ekwargs = event.kwargs

        retval = None
        handler = None

        for handler in self._getHandlers(channel):
            attrs = self._handlerattrs[handler]
            event.handler = handler
            try:
                if attrs["event"]:
                    retval = handler(event, *eargs, **ekwargs)
                else:
                    retval = handler(*eargs, **ekwargs)
                event.value.value = retval
            except (KeyboardInterrupt, SystemExit):
                raise
            except:
                etype, evalue, etraceback = _exc_info()
                event.value.errors = True
                event.value.value = etype, evalue, format_tb(etraceback)
                self.fire(Error(etype, evalue, format_tb(etraceback), handler))
                if event.failure is not None:
                    error = (etype, evalue, format_tb(etraceback))
                    self.fire(Failure(event, handler, error), *event.failure)

            if retval is not None:
                if retval and attrs["filter"]:
                    if event.filter is not None:
                        self.fire(Filter(event, handler, retval), *event.filter)
                    return  # Filter
                if event.success is not None:
                    self.fire(Success(event, handler, retval), *event.success)

        if event.end is not None:
            self.fire(End(event, handler, retval), *event.end)
开发者ID:AlphaStaxLLC,项目名称:TundraAddons,代码行数:37,代码来源:manager.py


示例20: error

 def error(self):
     """
     Logs the current exception info
     """
     exc = _exc_info()
     self.logger.error("".join(_traceback.format_exception(*exc)))
开发者ID:AlexSnet,项目名称:headstock,代码行数:6,代码来源:logger.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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