def open(self): if self.request.headers['Origin'] != 'http://%s' % ( self.request.headers['Host']): self.close() return self.uuid = str(uuid4()) syncwebsockets.add(self.uuid, self) if not LibPythonWatcher: syncwebsockets.send(self.uuid, 'StartLoop')
def refresh_process(uuid=None): if uuid is not None: send = lambda cmd, data: syncwebsockets.send(uuid, cmd, data) else: send = syncwebsockets.broadcast remaining_pids = [] remaining_tids = [] for proc in psutil.process_iter(): cl = proc.cmdline() if len(cl) == 0: continue binary = cl[0].split('/')[-1] if (('python' in binary or 'pypy' in binary) and proc.is_running() and proc.status() != psutil.STATUS_ZOMBIE): try: send( 'AddProcess', { 'pid': proc.pid, 'user': proc.username(), 'cmd': ' '.join(proc.cmdline()), 'threads': proc.num_threads(), 'time': proc.create_time(), 'mem': proc.memory_percent(), 'cpu': proc.cpu_percent(interval=.01) }) remaining_pids.append(proc.pid) for thread in proc.threads(): send('AddThread', {'id': thread.id, 'of': proc.pid}) remaining_tids.append(thread.id) except: log.warn('', exc_info=True) continue send('KeepProcess', remaining_pids) send('KeepThreads', remaining_tids)
def on_message(self, message): if '|' in message: cmd, data = message.split('|', 1) else: cmd, data = message, '' if cmd == 'ListSockets': for uuid in sockets.uuids: syncwebsockets.send(self.uuid, 'AddSocket', uuid) elif cmd == 'ListWebsockets': for uuid in websockets.uuids: syncwebsockets.send(self.uuid, 'AddWebSocket', uuid) elif cmd == 'ListBreaks': for brk in breakpoints.get(): syncwebsockets.send(self.uuid, 'AddBreak', brk) elif cmd == 'RemoveBreak': brk = json.loads(data) breakpoints.remove(brk) # If it was here, it wasn't temporary brk['temporary'] = False sockets.broadcast('Unbreak', brk) elif cmd == 'RemoveUUID': sockets.close(data) sockets.remove(data) websockets.close(data) websockets.remove(data) elif cmd == 'ListProcesses': refresh_process(self.uuid) elif cmd == 'Pause': if int(data) == os.getpid(): log.debug('Pausing self') def self_shell(variables): # Debugging self import wdb wdb.set_trace() Process(target=self_shell, args=(globals(),)).start() else: log.debug('Pausing %s' % data) tornado.process.Subprocess([ 'gdb', '-p', data, '-batch'] + [ "-eval-command=call %s" % hook for hook in [ 'PyGILState_Ensure()', 'PyRun_SimpleString(' '"import wdb; wdb.set_trace(skip=1)"' ')', 'PyGILState_Release($1)', ]]) elif cmd == 'RunFile': file_name = data def run(): from wdb import Wdb Wdb.get().run_file(file_name) Process(target=run).start()
def refresh_process(uuid=None): if uuid is not None: send = lambda cmd, data: syncwebsockets.send(uuid, cmd, data) else: send = syncwebsockets.broadcast remaining_pids = [] remaining_tids = [] for proc in psutil.process_iter(): try: cl = proc.cmdline() except (psutil.ZombieProcess, psutil.AccessDenied, psutil.NoSuchProcess): continue else: if len(cl) == 0: continue binary = cl[0].split('/')[-1] if ( ('python' in binary or 'pypy' in binary) and proc.is_running() and proc.status() != psutil.STATUS_ZOMBIE): try: try: cpu = proc.cpu_percent(interval=.01) send('AddProcess', { 'pid': proc.pid, 'user': proc.username(), 'cmd': ' '.join(proc.cmdline()), 'threads': proc.num_threads(), 'time': proc.create_time(), 'mem': proc.memory_percent(), 'cpu': cpu }) remaining_pids.append(proc.pid) for thread in proc.threads(): send('AddThread', { 'id': thread.id, 'of': proc.pid }) remaining_tids.append(thread.id) except psutil.NoSuchProcess: pass except Exception: log.warn('', exc_info=True) continue send('KeepProcess', remaining_pids) send('KeepThreads', remaining_tids)
def on_open(self): self.uuid = str(uuid4()) syncwebsockets.add(self.uuid, self) if not LibPythonWatcher: syncwebsockets.send(self.uuid, 'StartLoop')