Package roslaunch :: Module child
[frames] | no frames]

Source Code for Module roslaunch.child

  1  # Software License Agreement (BSD License) 
  2  # 
  3  # Copyright (c) 2008, Willow Garage, Inc. 
  4  # All rights reserved. 
  5  # 
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions 
  8  # are met: 
  9  # 
 10  #  * Redistributions of source code must retain the above copyright 
 11  #    notice, this list of conditions and the following disclaimer. 
 12  #  * Redistributions in binary form must reproduce the above 
 13  #    copyright notice, this list of conditions and the following 
 14  #    disclaimer in the documentation and/or other materials provided 
 15  #    with the distribution. 
 16  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 17  #    contributors may be used to endorse or promote products derived 
 18  #    from this software without specific prior written permission. 
 19  # 
 20  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 21  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 22  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 23  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 24  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 25  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 26  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 27  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 28  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 29  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 30  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  # POSSIBILITY OF SUCH DAMAGE. 
 32  # 
 33  # Revision $Id: child.py 9195 2010-04-19 18:25:24Z kwc $ 
 34   
 35  """ 
 36  ROSLaunch child server. 
 37   
 38  ROSLaunch has a client/server architecture for running remote 
 39  processes. When a user runs roslaunch, this creates a "parent" 
 40  roslaunch process. This parent process will then start "child" 
 41  processes on remote machines. The parent can then invoke methods on 
 42  this child process to launch remote processes, and the child can 
 43  invoke methods on the parent to provide feedback. 
 44  """ 
 45   
 46  import logging 
 47  import sys 
 48  import time 
 49  import traceback 
 50   
 51  import roslaunch.core  
 52  import roslaunch.pmon 
 53  import roslaunch.server 
 54   
55 -class ROSLaunchChild(object):
56 """ 57 ROSLaunchChild infrastructure. 58 59 This must be called from the Python Main thread due to signal registration. 60 """ 61
62 - def __init__(self, run_id, name, server_uri):
63 """ 64 Startup roslaunch remote client XML-RPC services. Blocks until shutdown 65 @param run_id: UUID of roslaunch session 66 @type run_id: str 67 @param name: name of remote client 68 @type name: str 69 @param server_uri: XML-RPC URI of roslaunch server 70 @type server_uri: str 71 @return: XML-RPC URI 72 @rtype: str 73 """ 74 roslaunch.core.set_child_mode(True) 75 76 self.logger = logging.getLogger("roslaunch.child") 77 self.run_id = run_id 78 self.name = name 79 self.server_uri = server_uri 80 self.child_server = None 81 self.pm = None 82 83 roslaunch.pmon._init_signal_handlers()
84
85 - def _start_pm(self):
86 """ 87 Start process monitor for child roslaunch 88 """ 89 # start process monitor 90 # - this test is mainly here so that testing logic can 91 # override process monitor with a mock 92 if self.pm is None: 93 self.pm = roslaunch.pmon.start_process_monitor() 94 if self.pm is None: 95 # this should only happen if a shutdown signal is received during startup 96 raise roslaunch.core.RLException("cannot startup remote child: unable to start process monitor.") 97 self.logger.debug("started process monitor")
98
99 - def run(self):
100 """ 101 Runs child. Blocks until child processes exit. 102 """ 103 try: 104 try: 105 self.logger.info("starting roslaunch child process [%s], server URI is [%s]", self.name, self.server_uri) 106 self._start_pm() 107 self.child_server = roslaunch.server.ROSLaunchChildNode(self.run_id, self.name, self.server_uri, self.pm) 108 self.logger.info("... creating XMLRPC server for child") 109 self.child_server.start() 110 self.logger.info("... started XMLRPC server for child") 111 # block until process monitor is shutdown 112 self.pm.mainthread_spin() 113 self.logger.info("... process monitor is done spinning") 114 except: 115 self.logger.error(traceback.format_exc()) 116 raise 117 finally: 118 if self.pm: 119 self.pm.shutdown() 120 self.pm.join() 121 if self.child_server: 122 self.child_server.shutdown('roslaunch child complete')
123
124 - def shutdown(self):
125 if self.pm: 126 self.pm.shutdown() 127 self.pm.join()
128