本文整理汇总了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