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 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
55 """
56 ROSLaunchChild infrastructure.
57
58 This must be called from the Python Main thread due to signal registration.
59 """
60
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
92 """
93 Start process monitor for child roslaunch
94 """
95
96
97
98 if self.pm is None:
99 self.pm = roslaunch.pmon.start_process_monitor()
100 if self.pm is None:
101
102 raise roslaunch.core.RLException("cannot startup remote child: unable to start process monitor.")
103 self.logger.debug("started process monitor")
104
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
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
133 if self.pm:
134 self.pm.shutdown()
135 self.pm.join()
136