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$ 
 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 traceback 
 48   
 49  import roslaunch.core 
 50  import roslaunch.pmon 
 51  import roslaunch.server 
 52  from roslaunch.nodeprocess import DEFAULT_TIMEOUT_SIGINT, DEFAULT_TIMEOUT_SIGTERM 
 53   
54 -class ROSLaunchChild(object):
55 """ 56 ROSLaunchChild infrastructure. 57 58 This must be called from the Python Main thread due to signal registration. 59 """ 60
61 - def __init__(self, run_id, name, server_uri, sigint_timeout=DEFAULT_TIMEOUT_SIGINT, sigterm_timeout=DEFAULT_TIMEOUT_SIGTERM):
62 """ 63 Startup roslaunch remote client XML-RPC services. Blocks until shutdown 64 @param run_id: UUID of roslaunch session 65 @type run_id: str 66 @param name: name of remote client 67 @type name: str 68 @param server_uri: XML-RPC URI of roslaunch server 69 @type server_uri: str 70 @param sigint_timeout: The SIGINT timeout used when killing nodes (in seconds). 71 @type sigint_timeout: float 72 @param sigterm_timeout: The SIGTERM timeout used when killing nodes if SIGINT does not stop the node ( 73 in seconds). 74 @type sigterm_timeout: float 75 @return: XML-RPC URI 76 @rtype: str 77 """ 78 roslaunch.core.set_child_mode(True) 79 80 self.logger = logging.getLogger("roslaunch.child") 81 self.run_id = run_id 82 self.name = name 83 self.server_uri = server_uri 84 self.child_server = None 85 self.pm = None 86 self.sigint_timeout = sigint_timeout 87 self.sigterm_timeout = sigterm_timeout 88 89 roslaunch.pmon._init_signal_handlers()
90
91 - def _start_pm(self):
92 """ 93 Start process monitor for child roslaunch 94 """ 95 # start process monitor 96 # - this test is mainly here so that testing logic can 97 # override process monitor with a mock 98 if self.pm is None: 99 self.pm = roslaunch.pmon.start_process_monitor() 100 if self.pm is None: 101 # this should only happen if a shutdown signal is received during startup 102 raise roslaunch.core.RLException("cannot startup remote child: unable to start process monitor.") 103 self.logger.debug("started process monitor")
104
105 - def run(self):
106 """ 107 Runs child. Blocks until child processes exit. 108 """ 109 try: 110 try: 111 self.logger.info("starting roslaunch child process [%s], server URI is [%s]", self.name, self.server_uri) 112 self._start_pm() 113 self.child_server = roslaunch.server.ROSLaunchChildNode(self.run_id, self.name, self.server_uri, 114 self.pm, sigint_timeout=self.sigint_timeout, 115 sigterm_timeout=self.sigterm_timeout) 116 self.logger.info("... creating XMLRPC server for child") 117 self.child_server.start() 118 self.logger.info("... started XMLRPC server for child") 119 # block until process monitor is shutdown 120 self.pm.mainthread_spin() 121 self.logger.info("... process monitor is done spinning") 122 except: 123 self.logger.error(traceback.format_exc()) 124 raise 125 finally: 126 if self.pm: 127 self.pm.shutdown() 128 self.pm.join() 129 if self.child_server: 130 self.child_server.shutdown('roslaunch child complete')
131
132 - def shutdown(self):
133 if self.pm: 134 self.pm.shutdown() 135 self.pm.join()
136