39 import roslib; roslib.load_manifest(PKG)
43 from optparse
import OptionParser
52 from roslaunch.config
import ROSLaunchConfig
54 import roslaunch.parent
55 from roslaunch.pmon
import pmon_shutdown
as _pmon_shutdown
58 from launchman
import app
79 package, launch_file = string.split(self.app.launch_file,
"/", 1)
80 path = app.getPackagePath(package)
82 print "launchfile", launch_file
84 fn = os.path.join(path, launch_file)
85 if not os.path.exists(fn):
88 self.
runner = roslaunch.parent.ROSLaunchParent(rospy.get_param(
"/run_id"), [fn], is_core=
False, process_listeners=(self, ))
95 print "no runner", self
97 self.runner.shutdown()
101 rospy.logerr(
"process_died, but we're ignoring this: %s, %s" % ( process_name, exit_code))
104 rospy.logdebug(
"process_died: %s, %s" % ( process_name, exit_code))
105 if self.
runner: rospy.logdebug(self.runner.pm.procs)
107 if not self.
runner:
return 109 if len(self.runner.pm.procs) == 1:
112 self.runner.shutdown()
113 except Exception
as e:
118 self.manager._stopTask(self)
120 if self.runner.pm.procs:
121 self.task.status =
"error" 122 self.manager._send_status()
124 print "too many processes left:", len(self.runner.pm.procs)
125 for proc
in self.runner.pm.procs:
130 self.runner.shutdown()
131 except Exception
as e:
135 self.manager._stopTask(self)
140 return "<AppRunner %s: %s %s %s>" % (self.
taskid, self.app.provides, self.app.taskid, len(self.
childGroups))
146 self.
app_update = rospy.Publisher(
"app_update", AppUpdate, self)
147 self.
app_status = rospy.Publisher(
"app_status", AppStatus, self)
154 for taskid, runner
in self._apps.items():
155 apps.append(
Application(taskid, runner.app.name, runner.task.status, runner.app.icon, str(runner.app.provides), str(runner.app.depends)))
156 self.app_status.publish(apps)
173 return tuple(d), pgroup
189 for runner
in pgroup:
190 if runner.task.taskid == req.taskid:
191 print "already running" 198 return StartTaskResponse(
"The %s app conflicts with the %s app; please stop the %s app"%(a.name, runner.app.name, runner.app.name))
204 print "no parent task group %s running" % str(uncovered)
210 self.
_apps[req.taskid] = runner
217 p.childGroups.append(runner)
220 runner.task.taskid = req.taskid
221 runner.task.username = req.username
222 runner.task.started = rospy.get_rostime()
223 runner.task.status =
"starting" 230 except Exception
as e:
232 traceback.print_exc()
233 runner.task.status =
"error" 238 return StartTaskResponse(
"Exception while trying to launch the %s app: \"%s\""%(req.taskid, e))
240 runner.task.status =
"running" 248 for provides, runner
in self._taskGroups.items():
249 print provides, runner.childGroups
252 runner.task.status =
"stopping" 256 for cgroup
in runner.childGroups[:]:
261 runner.task.status =
"stopped" 264 if runner.app.depends:
269 if runner
in p.childGroups:
270 p.childGroups.remove(runner)
272 if runner.app.provides:
273 print "removing", runner.app.provides
276 if runner.taskid
in self.
_apps:
277 del self.
_apps[runner.taskid]
278 print "removing", runner.taskid
282 if req.taskid
not in self.
_apps:
285 runner = self.
_apps[req.taskid]
308 rospy.init_node(NAME)
310 tm = TaskManager(kill_on_conflict)
311 s1 = rospy.Service(
'start_task', StartTask, tm.start_task)
312 s2 = rospy.Service(
'stop_task', StopTask, tm.stop_task)
313 s3 = rospy.Service(
'status_update', StatusUpdate, tm.status_update)
314 s4 = rospy.Service(
'list_tasks', ListTasks, tm.list_tasks)
319 if __name__ ==
"__main__":
320 parser = OptionParser(usage=
"usage: %prog [options]", prog=
'launchman.py')
321 parser.add_option(
"-k",
"--kill-on-conflict", dest=
"kill",
322 default=
False, action=
"store_true",
323 help=
"automatically kill conflicting tasks when starting a new task")
324 options, args = parser.parse_args()
326 roslaunch.pmon._init_signal_handlers()
def start_task(self, req)
def process_died(self, process_name, exit_code)
def peer_unsubscribe(self, topic_name, numPeers)
def peer_subscribe(self, topic_name, topic_publish, peer_publish)
def status_update(self, req)
def server(kill_on_conflict)
def __init__(self, manager, apprunner)
def _stopTask(self, runner)
def __init__(self, taskid, manager)
def list_tasks(self, req)
def __init__(self, kill_on_conflict=False)
def _find_providers(self, deps)