mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 07:36:23 -07:00
Catch KeyboardInterrupt exception in run_cmd and return normally
This commit is contained in:
parent
caaae0c547
commit
4949ccd1d4
1 changed files with 11 additions and 8 deletions
19
build.py
19
build.py
|
@ -149,14 +149,17 @@ def run_cmd(cmd, print_output=True, realtime=False, print_command=False):
|
||||||
status = 0
|
status = 0
|
||||||
if realtime: # print the command's output in real time, ignores print_output
|
if realtime: # print the command's output in real time, ignores print_output
|
||||||
while True:
|
while True:
|
||||||
realtime_output = proc.stdout.readline().decode("utf-8")
|
try:
|
||||||
if realtime_output == "" and status is not None:
|
realtime_output = proc.stdout.readline().decode("utf-8")
|
||||||
return ("", status)
|
if realtime_output == "" and status is not None:
|
||||||
if realtime_output:
|
return ("", status)
|
||||||
print(realtime_output.strip())
|
if realtime_output:
|
||||||
output += realtime_output
|
print(realtime_output.strip())
|
||||||
status = proc.poll()
|
output += realtime_output
|
||||||
else: # wait until the command is finished to print the output
|
status = proc.poll()
|
||||||
|
except KeyboardInterrupt as e:
|
||||||
|
return (output, 0)
|
||||||
|
else: # wait until the command is finished to print the output
|
||||||
output = proc.communicate()[0]
|
output = proc.communicate()[0]
|
||||||
if output is not None:
|
if output is not None:
|
||||||
output = output.decode("utf-8").strip()
|
output = output.decode("utf-8").strip()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue