def execute_command(cmd): try: running_command = subprocess.Popen(cmd) except WindowsError: running_command = subprocess.Popen(cmd + ".com") subprocess.terminate(running_command) return
def stop_etcd(subprocess, data_dir): if subprocess and subprocess.poll() is None: log.info(f"stopping etcd server") subprocess.terminate() subprocess.wait() log.info(f"deleting etcd data dir: {data_dir}") shutil.rmtree(data_dir, ignore_errors=True)
def _quit(): print("Closing App...") for subprocess in running_subprocesses: subprocess.terminate() # kill all running subprocesses app.df_songs.clear_all_youtube_links() app.df_songs.export_csv(file_path=".smartify.csv") root = Tk() root.quit() # stops mainloop root.destroy() # this is necessary on Windows to prevent # Fatal Python Error: PyEval_RestoreThread: NULL tstate os._exit(1)
def end_process(self, subprocess, signal=signal.SIGINT): print('ending process pid', subprocess.pid) ppid = subprocess.pid try: process = psutil.Process(ppid) except psutil.NoSuchProcess: return pids = process.children(recursive=True) for pid in pids: os.kill(pid.pid, signal) subprocess.terminate() try: subprocess.wait() except: subprocess.kill()
def end_process(self, subprocess, signal=signal.SIGSTOP): print('ending process pid', subprocess.pid) try: process = psutil.Process(subprocess.pid) except psutil.NoSuchProcess: print('process already stopped:', subprocess.pid) return command = process.cmdline() if 'ffmpeg' in command: print('ending ffmpeg recording gracefully') #subprocess.terminate() end_recording = subprocess.communicate(input=b'q') #print(end_recording) else: subprocess.terminate() self.running_processes.remove(subprocess) return
def main (args): ffserver = sp.Popen([FFSERVER_BIN, "-f", "ffserver.conf"]) _prepareTmpFolder() # create a threaded http server, each request is handled in a new thread httpd = ThreadedHttpServer((SERVER_IP, SERVER_PORT), RequestHandler) httpd.daemon_threads = True httpd.serve_forever() time.sleep(2) print "Everything is ready" try: while 1: time.sleep(.1) except KeyboardInterrupt: if ffserver is not None: sp.terminate() for channel, process in channels.iteritems(): if process is not None: process.terminate()
def test_execute_dont_kill_children(): pid = execute.python()(create_sleeper_subprocess)() subprocess = psutil.Process(pid) assert subprocess.status() == 'sleeping' subprocess.terminate() # cleanup
try: for worker in workers: worker.join() except KeyboardInterrupt: print("Not accepting any more jobs") try: while not job_queue.empty(): job_queue.get(block=False) except Queue.Empty: pass try: for worker in workers: worker.join() print("Finished pending jobs.") except KeyboardInterrupt: print("Killing pending jobs.") for worker in workers: worker.terminate() worker.join() while not process_queue.empty(): try: subprocess = process_queue.get(block=False) subprocess.terminate() except Queue.Empty: pass except OSError as e: # Deleting already dead process pass
text_address = 'tcp://127.0.0.1:5578' result_address = 'tcp://127.0.0.1:5579' subprocess_args = (sys.executable, main_file, '--text_address', text_address, '--result_address', result_address) subprocess = subprocess.Popen(subprocess_args) context = zmq.Context() text_socket = context.socket(zmq.PUB) text_socket.bind(text_address) result_socket = context.socket(zmq.SUB) result_socket.setsockopt(zmq.SUBSCRIBE, b'') result_socket.connect(result_address) # give our sockets a chance to connect sleep(1) example_text = b'This morning is easy like Sunday Morning' text_socket.send(example_text) result = result_socket.recv_pyobj() print(result) subprocess.terminate()
def exit_on_q(key): if key in ('q', 'Q'): subprocess.terminate() raise urwid.ExitMainLoop()
def terminate_subprocess(subprocess): if subprocess.poll() is None: subprocess.terminate()