def handle_process(self, proc, err):
"""
Takes a running subprocess.Popen object `proc`, rosdebugs everything it
prints to stdout, roswarns everything it prints to stderr, and raises
`err` if it fails
"""
poll = select.poll()
poll.register(proc.stdout)
poll.register(proc.stderr)
while proc.poll() is None and not rospy.is_shutdown():
res = poll.poll(1)
for fd, evt in res:
if not (evt & select.POLLIN):
continue
if fd == proc.stdout.fileno():
line = proc.stdout.readline().strip()
if line:
rospy.logdebug(line)
elif fd == proc.stderr.fileno():
line = proc.stderr.readline().strip()
if line:
rospy.logwarn(line)
if proc.poll():
proc.terminate()
proc.wait()
raise RuntimeError("Process interrupted by ROS shutdown")
if proc.returncode:
raise err
评论列表
文章目录