Skip to content

Commit

Permalink
Merge pull request #951 from jwm/kinetic-devel
Browse files Browse the repository at this point in the history
terminate underlying 'rosbag {play,record}' on SIGTERM
  • Loading branch information
dirk-thomas authored Jan 27, 2017
2 parents fb49cec + 8e42efa commit 8c430a8
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tools/rosbag/src/rosbag/rosbag_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def handle_split(option, opt_str, value, parser):
print("Use of \"--split <MAX_SIZE>\" has been deprecated. Please use --split --size <MAX_SIZE> or --split --duration <MAX_DURATION>", file=sys.stderr)
parser.values.size = int(parser.rargs.pop(0))


def _stop_process(signum, frame, old_handler, process):
process.terminate()
if old_handler:
old_handler(signum, frame)


def record_cmd(argv):
parser = optparse.OptionParser(usage="rosbag record TOPIC1 [TOPIC2 TOPIC3 ...]",
description="Record a bag file with the contents of specified topics.",
Expand Down Expand Up @@ -124,9 +131,15 @@ def record_cmd(argv):

cmd.extend(args)

old_handler = signal.signal(
signal.SIGTERM,
lambda signum, frame: _stop_process(signum, frame, old_handler, process)
)
# Better way of handling it than os.execv
# This makes sure stdin handles are passed to the process.
subprocess.call(cmd)
process = subprocess.Popen(cmd)
process.wait()


def info_cmd(argv):
parser = optparse.OptionParser(usage='rosbag info [options] BAGFILE1 [BAGFILE2 BAGFILE3 ...]',
Expand Down Expand Up @@ -257,9 +270,16 @@ def play_cmd(argv):
cmd.extend(['--bags'])

cmd.extend(args)

old_handler = signal.signal(
signal.SIGTERM,
lambda signum, frame: _stop_process(signum, frame, old_handler, process)
)
# Better way of handling it than os.execv
# This makes sure stdin handles are passed to the process.
subprocess.call(cmd)
process = subprocess.Popen(cmd)
process.wait()


def filter_cmd(argv):
def expr_eval(expr):
Expand Down

0 comments on commit 8c430a8

Please sign in to comment.