1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
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
86 """
87 Start process monitor for child roslaunch
88 """
89
90
91
92 if self.pm is None:
93 self.pm = roslaunch.pmon.start_process_monitor()
94 if self.pm is None:
95
96 raise roslaunch.core.RLException("cannot startup remote child: unable to start process monitor.")
97 self.logger.debug("started process monitor")
98
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
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
125 if self.pm:
126 self.pm.shutdown()
127 self.pm.join()
128