当前位置: 首页>>代码示例>>Python>>正文


Python BackdoorServer.serve_forever方法代码示例

本文整理汇总了Python中gevent.backdoor.BackdoorServer.serve_forever方法的典型用法代码示例。如果您正苦于以下问题:Python BackdoorServer.serve_forever方法的具体用法?Python BackdoorServer.serve_forever怎么用?Python BackdoorServer.serve_forever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gevent.backdoor.BackdoorServer的用法示例。


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

示例1: DebugService

# 需要导入模块: from gevent.backdoor import BackdoorServer [as 别名]
# 或者: from gevent.backdoor.BackdoorServer import serve_forever [as 别名]
class DebugService(RpcService):
    def __init__(self, gevent=False, builtins=None):
        self.gevent = gevent
        self.backdoor_locals = builtins or {}
        self.backdoor_server = None

    @private
    def attach(self, host, port):
        import pydevd
        pydevd.settrace(host, port=port, stdoutToServer=True, stderrToServer=True)

    @private
    def detach(self):
        import pydevd
        pydevd.stoptrace()

    @private
    def dump_stacks(self):
        if self.gevent:
            from greenlet import greenlet

            # If greenlet is present, let's dump each greenlet stack
            dump = []
            for ob in gc.get_objects():
                if not isinstance(ob, greenlet):
                    continue
                if not ob:
                    continue   # not running anymore or not started

                dump.append(''.join(traceback.format_stack(ob.gr_frame)))

            return dump
        else:
            dump = []
            for frame in list(sys._current_frames().values()):
                dump.append(''.join(traceback.format_stack(frame)))

            return dump

    @private
    def start_backdoor(self):
        if not self.gevent:
            raise RpcException(errno.ENOTSUP, 'Not supported')

        from gevent import spawn
        from gevent.backdoor import BackdoorServer
        self.backdoor_server = BackdoorServer(
            ('127.0.0.1', 9999),
            banner='DebugService backdoor server',
            locals=self.backdoor_locals
        )

        spawn(self.backdoor_server.serve_forever())

    @private
    def stop_backdoor(self):
        if not self.gevent:
            raise RpcException(errno.ENOTSUP, 'Not supported')

        if self.backdoor_server:
            self.backdoor_server.close()
            self.backdoor_server = None
开发者ID:650elx,项目名称:middleware,代码行数:64,代码来源:debug.py


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