1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 14:48:49 +00:00

#837: try and kill proc and its children

This commit is contained in:
Pablo S. Blum de Aguiar 2018-09-25 22:29:38 +02:00 committed by Pablo Santiago Blum de Aguiar
parent 00295f80b9
commit e7d508a9af

View File

@ -1,11 +1,25 @@
import os
import shlex
from subprocess import Popen, PIPE, STDOUT
from psutil import Process, TimeoutExpired
from psutil import AccessDenied, Process, TimeoutExpired
from .. import logs
from ..conf import settings
def _kill_process(proc):
"""Tries to kill the process otherwise just logs a debug message, the
process will be killed when thefuck terminates.
:type proc: Process
"""
try:
proc.kill()
except AccessDenied:
logs.debug(u'Rerun: process PID {} ({}) could not be terminated'.format(
proc.pid, proc.exe()))
def _wait_output(popen, is_slow):
"""Returns `True` if we can get output of the command in the
`settings.wait_command` time.
@ -23,8 +37,8 @@ def _wait_output(popen, is_slow):
return True
except TimeoutExpired:
for child in proc.children(recursive=True):
child.kill()
proc.kill()
_kill_process(child)
_kill_process(proc)
return False