python - Terminate a gnome-terminal opened with subprocess -
using subprocess , command 'gnome-terminal -e bash
' can open gnome-terminal desired (and have stick around). done either
p=subprocess.popen(['gnome-terminal', '-e', 'bash'])
or
p=subprocess.popen(['gnome-terminal -e bash'], shell=true)
but cannot close terminal using p.terminate()
or p.kill()
. understand, little trickier when using shell=true
did not expect run problems otherwise.
to terminate terminal , children (in same process group):
#!/usr/bin/env python import os import signal import subprocess p = subprocess.popen(['gnome-terminal', '--disable-factory', '-e', 'bash'], preexec_fn=os.setpgrp) # here... os.killpg(p.pid, signal.sigint)
--disable-factory
used avoid re-using active terminal can kill newly created terminal viasubprocess
handleos.setpgrp
putsgnome-terminal
in own process groupos.killpg()
used send signal group
Comments
Post a Comment