-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: implicit cli defaults and handlign orphaned python procs using s…
…h traps
- Loading branch information
Showing
3 changed files
with
27 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import subprocess | ||
import rospkg | ||
import os | ||
import rospkg | ||
import signal | ||
import subprocess | ||
import sys | ||
|
||
rospack = rospkg.RosPack() | ||
pcg_path = rospack.get_path("pcg") | ||
# move to pcg package directory | ||
os.chdir(pcg_path) | ||
args = ["sh", "./scripts/generate.py.sh", *sys.argv[1:]] | ||
if subprocess.run(args).returncode != 0: | ||
raise Exception("An error occured with running the script.") | ||
process = subprocess.Popen(args) | ||
try: | ||
process.wait() | ||
if process.returncode != 0: | ||
raise Exception("An error occured with running the script.") | ||
except KeyboardInterrupt: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -e | ||
|
||
# source the venv | ||
. venv/bin/activate | ||
|
||
python3 src/pcg/main.py $@ | ||
# handle sigint and sigterm; kill python proc | ||
control_c() { | ||
kill -9 $PID | ||
exit | ||
} | ||
|
||
trap "control_c" INT TERM | ||
|
||
python3 src/pcg/main.py "$@" & | ||
# capture PID of command to kill when this program is killed | ||
PID=$! | ||
wait "$PID" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters