Skip to content

Commit

Permalink
Merge pull request xonsh#3383 from xonsh/kill-win
Browse files Browse the repository at this point in the history
Fix ctrl-c traceback on windows
  • Loading branch information
gforsyth committed Nov 7, 2019
2 parents 104fbe7 + 20b226e commit f5d5ca1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 24 additions & 0 deletions news/kill-win.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fixed an issue on Windows where pressing ctrl-c could sometimes result
in a traceback if the process had already quit before being killed by xonsh.

**Security:**

* <news item>
10 changes: 8 additions & 2 deletions xonsh/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def _continue(job):
job["status"] = "running"

def _kill(job):
subprocess.check_output(["taskkill", "/F", "/T", "/PID", str(job["obj"].pid)])
subprocess.check_output(
["taskkill", "/F", "/T", "/PID", str(job["obj"].pid)],
stderr=subprocess.STDOUT,
)

def ignore_sigtstp():
pass
Expand All @@ -96,7 +99,10 @@ def wait_for_active_job(last_task=None, backgrounded=False):
except subprocess.TimeoutExpired:
pass
except KeyboardInterrupt:
_kill(active_task)
try:
_kill(active_task)
except subprocess.CalledProcessError:
pass # ignore error if process closed before we got here
return wait_for_active_job(last_task=active_task)


Expand Down

0 comments on commit f5d5ca1

Please sign in to comment.