mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-20 08:05:33 +03:00
Terminate madmax/bladebit on Windows on Ctrl-C (#9113)
This commit is contained in:
parent
c1796c3b63
commit
c80208cda9
@ -1,5 +1,7 @@
|
||||
import asyncio
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
# https://kevinmccarthy.org/2016/07/25/streaming-subprocess-stdin-and-stdout-with-asyncio-in-python/
|
||||
@ -21,10 +23,21 @@ def parse_stdout(out, progress):
|
||||
|
||||
|
||||
async def run_plotter(args, progress_dict):
|
||||
orig_sigint_handler = signal.getsignal(signal.SIGINT)
|
||||
installed_sigint_handler = False
|
||||
process = await asyncio.create_subprocess_exec(
|
||||
*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
|
||||
def sigint_handler(signum, frame):
|
||||
process.terminate()
|
||||
|
||||
# For Windows, we'll install a SIGINT handler to catch Ctrl-C (KeyboardInterrupt isn't raised)
|
||||
if sys.platform in ["win32", "cygwin"]:
|
||||
signal.signal(signal.SIGINT, sigint_handler)
|
||||
installed_sigint_handler = True
|
||||
|
||||
try:
|
||||
await asyncio.wait(
|
||||
[
|
||||
_read_stream(
|
||||
@ -39,6 +52,12 @@ async def run_plotter(args, progress_dict):
|
||||
)
|
||||
|
||||
await process.wait()
|
||||
except Exception as e:
|
||||
print(f"Caught exception while invoking plotter: {e}")
|
||||
finally:
|
||||
# Restore the original SIGINT handler
|
||||
if installed_sigint_handler:
|
||||
signal.signal(signal.SIGINT, orig_sigint_handler)
|
||||
|
||||
|
||||
def run_command(args, exc_description, *, check=True, **kwargs) -> subprocess.CompletedProcess:
|
||||
|
Loading…
Reference in New Issue
Block a user