small fix 20-06-26
This commit is contained in:
parent
7dca2744ce
commit
aca954d364
1 changed files with 56 additions and 0 deletions
|
|
@ -198,5 +198,61 @@ class SingboxRunner:
|
||||||
|
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
|
|
||||||
|
for pid in pids:
|
||||||
|
try:
|
||||||
|
subprocess.run(
|
||||||
|
['sudo', 'kill', '-9', str(pid)],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
env={**os.environ, 'SUDO_ASKPASS': '/bin/false'},
|
||||||
|
timeout=5,
|
||||||
|
)
|
||||||
|
except (OSError, subprocess.TimeoutExpired):
|
||||||
|
pass
|
||||||
|
|
||||||
|
except (OSError, ValueError, subprocess.TimeoutExpired):
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
['pgrep', '-x', 'sing-box'],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
pids = [
|
||||||
|
int(p)
|
||||||
|
for p in result.stdout.strip().splitlines()
|
||||||
|
if p.strip().isdigit()
|
||||||
|
]
|
||||||
|
|
||||||
|
if not pids:
|
||||||
|
return
|
||||||
|
|
||||||
|
subprocess.run(
|
||||||
|
['sudo', self._WRAPPER, '', 'stop'],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
env={**os.environ, 'SUDO_ASKPASS': '/bin/false'},
|
||||||
|
timeout=15,
|
||||||
|
)
|
||||||
|
|
||||||
|
deadline = time.monotonic() + 4.0
|
||||||
|
|
||||||
|
while time.monotonic() < deadline:
|
||||||
|
check = subprocess.run(
|
||||||
|
['pgrep', '-x', 'sing-box'],
|
||||||
|
capture_output=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if check.returncode != 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
time.sleep(0.3)
|
||||||
|
|
||||||
except (OSError, ValueError, subprocess.TimeoutExpired):
|
except (OSError, ValueError, subprocess.TimeoutExpired):
|
||||||
pass
|
pass
|
||||||
Loading…
Reference in a new issue