Skip to content

Commit

Permalink
Merge pull request fluidattacks#1289 from dacevedo12/main
Browse files Browse the repository at this point in the history
feat(build): fluidattacks#970 handle keyboard interrupt
  • Loading branch information
dsalaza4 authored Feb 9, 2024
2 parents 9f93d14 + 43b131a commit ca42c62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/cli/main/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from cli import (
main,
)
import sys

if __name__ == "__main__":
main(sys.argv)
try:
from cli import (
main,
)

main(sys.argv)
except KeyboardInterrupt:
sys.exit(130)
18 changes: 14 additions & 4 deletions src/cli/main/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,14 @@ def _run_outputs( # pylint: disable=too-many-arguments
stdout=stdout,
stderr=stderr,
) as process:
out, err = process.communicate(stdin)

return process.returncode, out, err
try:
out, err = process.communicate(stdin)
process.wait()
return process.returncode, out, err
except KeyboardInterrupt:
process.terminate()
process.wait()
return 130, bytes(), bytes()


def _run( # pylint: disable=too-many-arguments
Expand All @@ -459,7 +464,12 @@ def _run( # pylint: disable=too-many-arguments
stdout=stdout,
stderr=stderr,
) as process:
return process.wait()
try:
return process.wait()
except KeyboardInterrupt:
process.terminate()
process.wait()
return 130


def _help_and_exit_base() -> None:
Expand Down

0 comments on commit ca42c62

Please sign in to comment.