本文整理匯總了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