I’m a little bit lost here, are you guys using ExecCommand
to run your build_systems? Because if it’s so such command already implements the kill action, i.e:
def kill(self):
if not self.killed:
self.killed = True
if sys.platform == "win32":
# terminate would not kill process opened by the shell cmd.exe,
# it will only kill cmd.exe leaving the child running
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.Popen(
"taskkill /PID " + str(self.proc.pid),
startupinfo=startupinfo)
else:
self.proc.terminate()
self.listener = None
The python spawned process is killed in a multiplatform way, if I’m not mistaken this method is being called when using Tools\Cancel build
(ctrl+break).
A while ago I had faced something similar, some build_systems were using my own ExecCommand subclass so my solution had been adding something like this:
class ZebraVirtualenvCancelCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("zebra_virtualenv_exec", {"kill": True})
def is_enabled(self):
return True
That way I could bind this command to a key shortcut and killing my process spawned by my own ExecCommand subclass. In any case, as I’ve said, if you’re using the default ExecCommand (default command) just use its own implementation through Cancel build
, which is more than good enough for a big number of cases.