Skip to content

Commit

Permalink
Trying to get the subprocess of Singular killed on keyboard interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
GDeLaurentis committed Jan 27, 2025
1 parent 3c43dbe commit 9e81129
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion syngular/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ def execute_singular_command(singular_command, timeout='default', verbose=False)
test = subprocess.Popen(["timeout", str(timeout), "Singular", "--quiet", file_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
else:
test = subprocess.Popen(["timeout", str(timeout), "Singular", "--quiet", "--execute", singular_command], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
output = test.communicate()[0]
try:
output = test.communicate()[0]
except KeyboardInterrupt:
print("Keyboard interrupt received. Terminating the Singular process.")
if test.poll() is None: # Check if the process is still running
import os
import signal
os.kill(test.pid, signal.SIGTERM)
raise KeyboardInterrupt
output = output.decode("utf-8")
if output[-1] == "\n":
output = output[:-1]
Expand Down

0 comments on commit 9e81129

Please sign in to comment.