diff options
Diffstat (limited to 'bitbake')
-rwxr-xr-x | bitbake/lib/bb/main.py | 7 | ||||
-rw-r--r-- | bitbake/lib/bb/server/xmlrpc.py | 19 |
2 files changed, 22 insertions, 4 deletions
diff --git a/bitbake/lib/bb/main.py b/bitbake/lib/bb/main.py index 849cade8ca..7f7d87bd02 100755 --- a/bitbake/lib/bb/main.py +++ b/bitbake/lib/bb/main.py | |||
@@ -253,6 +253,10 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters): | |||
253 | parser.add_option("-B", "--bind", action="store", dest="bind", default=False, | 253 | parser.add_option("-B", "--bind", action="store", dest="bind", default=False, |
254 | help="The name/address for the bitbake server to bind to.") | 254 | help="The name/address for the bitbake server to bind to.") |
255 | 255 | ||
256 | parser.add_option("-T", "--idle-timeout", type=int, | ||
257 | default=int(os.environ.get("BBTIMEOUT", "0")), | ||
258 | help="Set timeout to unload bitbake server due to inactivity") | ||
259 | |||
256 | parser.add_option("", "--no-setscene", action="store_true", | 260 | parser.add_option("", "--no-setscene", action="store_true", |
257 | dest="nosetscene", default=False, | 261 | dest="nosetscene", default=False, |
258 | help="Do not run any setscene tasks. sstate will be ignored and " | 262 | help="Do not run any setscene tasks. sstate will be ignored and " |
@@ -337,7 +341,8 @@ def start_server(servermodule, configParams, configuration, features): | |||
337 | single_use = not configParams.server_only and os.getenv('BBSERVER') != 'autostart' | 341 | single_use = not configParams.server_only and os.getenv('BBSERVER') != 'autostart' |
338 | if configParams.bind: | 342 | if configParams.bind: |
339 | (host, port) = configParams.bind.split(':') | 343 | (host, port) = configParams.bind.split(':') |
340 | server.initServer((host, int(port)), single_use=single_use) | 344 | server.initServer((host, int(port)), single_use=single_use, |
345 | idle_timeout=configParams.idle_timeout) | ||
341 | configuration.interface = [server.serverImpl.host, server.serverImpl.port] | 346 | configuration.interface = [server.serverImpl.host, server.serverImpl.port] |
342 | else: | 347 | else: |
343 | server.initServer(single_use=single_use) | 348 | server.initServer(single_use=single_use) |
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py index 4131b52679..452f14bb32 100644 --- a/bitbake/lib/bb/server/xmlrpc.py +++ b/bitbake/lib/bb/server/xmlrpc.py | |||
@@ -205,7 +205,7 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
205 | # remove this when you're done with debugging | 205 | # remove this when you're done with debugging |
206 | # allow_reuse_address = True | 206 | # allow_reuse_address = True |
207 | 207 | ||
208 | def __init__(self, interface, single_use=False): | 208 | def __init__(self, interface, single_use=False, idle_timeout=0): |
209 | """ | 209 | """ |
210 | Constructor | 210 | Constructor |
211 | """ | 211 | """ |
@@ -223,6 +223,10 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
223 | self.commands = BitBakeServerCommands(self) | 223 | self.commands = BitBakeServerCommands(self) |
224 | self.autoregister_all_functions(self.commands, "") | 224 | self.autoregister_all_functions(self.commands, "") |
225 | self.interface = interface | 225 | self.interface = interface |
226 | self.time = time.time() | ||
227 | self.idle_timeout = idle_timeout | ||
228 | if idle_timeout: | ||
229 | self.register_idle_function(self.handle_idle_timeout, self) | ||
226 | 230 | ||
227 | def addcooker(self, cooker): | 231 | def addcooker(self, cooker): |
228 | BaseImplServer.addcooker(self, cooker) | 232 | BaseImplServer.addcooker(self, cooker) |
@@ -238,6 +242,12 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
238 | if name.startswith(prefix): | 242 | if name.startswith(prefix): |
239 | self.register_function(method, name[len(prefix):]) | 243 | self.register_function(method, name[len(prefix):]) |
240 | 244 | ||
245 | def handle_idle_timeout(self, server, data, abort): | ||
246 | if not abort: | ||
247 | if time.time() - server.time > server.idle_timeout: | ||
248 | server.quit = True | ||
249 | print("Server idle timeout expired") | ||
250 | return [] | ||
241 | 251 | ||
242 | def serve_forever(self): | 252 | def serve_forever(self): |
243 | # Start the actual XMLRPC server | 253 | # Start the actual XMLRPC server |
@@ -280,6 +290,8 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
280 | try: | 290 | try: |
281 | fd_sets = select.select(fds, [], [], socktimeout) | 291 | fd_sets = select.select(fds, [], [], socktimeout) |
282 | if fd_sets[0] and self in fd_sets[0]: | 292 | if fd_sets[0] and self in fd_sets[0]: |
293 | if self.idle_timeout: | ||
294 | self.time = time.time() | ||
283 | self._handle_request_noblock() | 295 | self._handle_request_noblock() |
284 | except IOError: | 296 | except IOError: |
285 | # we ignore interrupted calls | 297 | # we ignore interrupted calls |
@@ -351,9 +363,10 @@ class BitBakeXMLRPCServerConnection(BitBakeBaseServerConnection): | |||
351 | pass | 363 | pass |
352 | 364 | ||
353 | class BitBakeServer(BitBakeBaseServer): | 365 | class BitBakeServer(BitBakeBaseServer): |
354 | def initServer(self, interface = ("localhost", 0), single_use = False): | 366 | def initServer(self, interface = ("localhost", 0), |
367 | single_use = False, idle_timeout=0): | ||
355 | self.interface = interface | 368 | self.interface = interface |
356 | self.serverImpl = XMLRPCServer(interface, single_use) | 369 | self.serverImpl = XMLRPCServer(interface, single_use, idle_timeout) |
357 | 370 | ||
358 | def detach(self): | 371 | def detach(self): |
359 | daemonize.createDaemon(self.serverImpl.serve_forever, "bitbake-cookerdaemon.log") | 372 | daemonize.createDaemon(self.serverImpl.serve_forever, "bitbake-cookerdaemon.log") |