1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-19 09:08:47 +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 os
import shlex import shlex
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
from psutil import Process, TimeoutExpired from psutil import AccessDenied, Process, TimeoutExpired
from .. import logs from .. import logs
from ..conf import settings 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): def _wait_output(popen, is_slow):
"""Returns `True` if we can get output of the command in the """Returns `True` if we can get output of the command in the
`settings.wait_command` time. `settings.wait_command` time.
@ -23,8 +37,8 @@ def _wait_output(popen, is_slow):
return True return True
except TimeoutExpired: except TimeoutExpired:
for child in proc.children(recursive=True): for child in proc.children(recursive=True):
child.kill() _kill_process(child)
proc.kill() _kill_process(proc)
return False return False