def test(): queue = Queue() proc = Process(target=doNothing, args=(queue, )) proc.start() _logger.info("Started dummy process with PID %d", proc.pid) startCodeCheckerServerAttachedToPid(proc.pid) time.sleep(3) _logger.info("Allowing the dummy process to finish") queue.put(1) proc.join() if utils.isProcessRunning(proc.pid): _logger.warning("Dummy process %d was still running", proc.pid) proc.terminate() time.sleep(1) it.assertFalse(utils.isProcessRunning(proc.pid), "Process %d is still running after terminating " "it!" % proc.pid) time.sleep(1) _logger.info("Server should have died by now") with it.assertRaises(requests.ConnectionError): requests.post(it._url + '/get_diagnose_info')
def _watchPidWrapper(): "PID attachment monitor" try: if utils.isProcessRunning(source_pid): Timer(1, _watchPidWrapper).start() else: _logger.warning("Process %d is not running anymore", source_pid) utils.terminateProcess(target_pid) except (TypeError, AttributeError): # pragma: no cover return