def fork_server(): pid = os.fork() if not pid: server = TCPServer() server.commands = {'add': TestTCPHandlerSimple, 'cpu': TestTCPHandlerCPU} server.listen() else: try: time.sleep(2) run_tests() except Exception: print "TESTS FAILED" raise os.kill(pid, signal.SIGKILL)
# Get memory usage until the parent tells us to stop or we timeout. max_mem = self.start_mem self.conn.sock.settimeout(1.0 / 10000) while True: curr_mem = get_memory_usage(self.proc_to_watch) max_mem = max(curr_mem, max_mem) # Poll for stop signal try: self.recv() break except: continue # Send the results back to the parent. return self.success(peak_usage=max_mem - self.start_mem) except Exception as e: msg = e.message if not msg: msg = "Memory Profiler process died watching %d!" % self.proc_to_watch logger.error(msg) return self.error(msg) if __name__ == "__main__": server = TCPServer(PROFILER_HOST, PROFILER_PORT) server.commands = { 'profile': MemoryProfiler } server.listen()