mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-06-27 08:50:43 -04:00
Updated keyboard interrupt handling code
This commit is contained in:
parent
2964a0c9ec
commit
db49fd6b03
1 changed files with 19 additions and 1 deletions
20
bazarr.py
20
bazarr.py
|
@ -107,6 +107,22 @@ def check_status():
|
|||
child_process = start_bazarr()
|
||||
|
||||
|
||||
def is_process_running(pid):
|
||||
commands = {
|
||||
"win": ["tasklist", "/FI", f"PID eq {pid}"],
|
||||
"linux": ["ps", "-eo", "pid"],
|
||||
"darwin": ["ps", "-ax", "-o", "pid"]
|
||||
}
|
||||
|
||||
# Determine OS and execute corresponding command
|
||||
for key in commands:
|
||||
if sys.platform.startswith(key):
|
||||
result = subprocess.run(commands[key], capture_output=True, text=True)
|
||||
return str(pid) in result.stdout.split()
|
||||
|
||||
print("Unsupported OS")
|
||||
return False
|
||||
|
||||
def interrupt_handler(signum, frame):
|
||||
# catch and ignore keyboard interrupt Ctrl-C
|
||||
# the child process Server object will catch SIGINT and perform an orderly shutdown
|
||||
|
@ -116,7 +132,9 @@ def interrupt_handler(signum, frame):
|
|||
interrupted = True
|
||||
print('Handling keyboard interrupt...')
|
||||
else:
|
||||
print("Stop doing that! I heard you the first time!")
|
||||
if not is_process_running(child_process):
|
||||
# this will be caught by the main loop below
|
||||
raise SystemExit(EXIT_INTERRUPT)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue