class Warpgate(object): def init(self): import options from UnityEngine import Debug L = lambda s: Debug.Log("PyWrap: " + s) L("init") self.events = [] # should set them options.no_update options.show_hidden_mode options.freeplay = False if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate L("before gevent") from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() L("after gevent") from game import autoenv autoenv.init('Client') import thb.ui.ui_meta # noqa, init ui_meta from client.core.executive import Executive self.executive = ExecutiveWrapper(Executive, self) def get_events(self): l = self.events self.events = [] return l def start_backdoor(self): from gevent.backdoor import BackdoorServer import gevent self.bds = BackdoorServer(('127.0.0.1', 12345)) self.gr_bds = gevent.spawn(self.bds.serve_forever) def stop_backdoor(self): self.gr_bds.kill() self.bds.close() def shutdown(self): from client.core.executive import Executive if Executive.state == 'connected': Executive.disconnect() def queue_system_event(self, evt_name, arg=None): self.events.append(('system_event', evt_name, arg))
class DebugService(RpcService): def __init__(self): super(DebugService, self).__init__() self.dispatcher = None self.backdoor_server = None def initialize(self, context): self.dispatcher = context.dispatcher @private def dump_stacks(self): 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 @private def attach(self, host, port): sys.path.append('/usr/local/lib/dispatcher/pydev') import pydevd pydevd.settrace(host, port=port, stdoutToServer=True, stderrToServer=True) @private def detach(self): import pydevd pydevd.stoptrace() @private def set_tasks_debug(self, host, port, tasks=None): self.dispatcher.balancer.debugger = (host, port) self.dispatcher.balancer.debugged_tasks = tasks or ['*'] @private def cancel_tasks_debug(self): self.dispatcher.balancer.debugger = None self.dispatcher.balancer.debugged_tasks = None @private def start_backdoor(self): self.backdoor_server = BackdoorServer( ('127.0.0.1', 9999), banner='DebugService backdoor server', locals={'dispatcher': self.dispatcher}) gevent.spawn(self.backdoor_server.serve_forever) @private def stop_backdoor(self): if self.backdoor_server: self.backdoor_server.close() self.backdoor_server = None @private def start_tracemalloc(self): tracemalloc.start() @private def stop_tracemalloc(self): tracemalloc.stop() @private def snapshot_tracemalloc(self): snap = tracemalloc.take_snapshot() return [str(i) for i in snap.statistics('lineno')[:100]]
class DebugService(RpcService): def __init__(self): super(DebugService, self).__init__() self.dispatcher = None self.backdoor_server = None def initialize(self, context): self.dispatcher = context.dispatcher @private def dump_stacks(self): 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 @private def attach(self, host, port): sys.path.append('/usr/local/lib/dispatcher/pydev') import pydevd pydevd.settrace(host, port=port, stdoutToServer=True, stderrToServer=True) @private def detach(self): import pydevd pydevd.stoptrace() @private def set_tasks_debug(self, host, port, tasks=None): self.dispatcher.balancer.debugger = (host, port) self.dispatcher.balancer.debugged_tasks = tasks or ['*'] @private def cancel_tasks_debug(self): self.dispatcher.balancer.debugger = None self.dispatcher.balancer.debugged_tasks = None @private def start_backdoor(self): self.backdoor_server = BackdoorServer( ('127.0.0.1', 9999), banner='DebugService backdoor server', locals={ 'dispatcher': self.dispatcher } ) gevent.spawn(self.backdoor_server.serve_forever) @private def stop_backdoor(self): if self.backdoor_server: self.backdoor_server.close() self.backdoor_server = None @private def start_tracemalloc(self): tracemalloc.start() @private def stop_tracemalloc(self): tracemalloc.stop() @private def snapshot_tracemalloc(self): snap = tracemalloc.take_snapshot() return [str(i) for i in snap.statistics('lineno')[:100]]
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
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 @private def start_tracemalloc(self): tracemalloc.start() @private def stop_tracemalloc(self): tracemalloc.stop() @private def snapshot_tracemalloc(self): snap = tracemalloc.take_snapshot() return [str(i) for i in snap.statistics('lineno')[:100]]