summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2011-06-08 11:20:08 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-06-08 11:38:47 +0100
commit658ba779ac98803e82fb3f17860a72f178f97d5b (patch)
tree983f60549757416ab2fbca9befeaf08c19cffa52 /bitbake/lib
parent8aabfed148ddbc42ea8ed28d7ea23193f1cdd87d (diff)
downloadast2050-yocto-poky-658ba779ac98803e82fb3f17860a72f178f97d5b.zip
ast2050-yocto-poky-658ba779ac98803e82fb3f17860a72f178f97d5b.tar.gz
bitbake/server/process: Update to new server API
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/server/process.py107
1 files changed, 75 insertions, 32 deletions
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py
index 5d7f8aa..12f368f 100644
--- a/bitbake/lib/bb/server/process.py
+++ b/bitbake/lib/bb/server/process.py
@@ -29,8 +29,8 @@ import os
import signal
import sys
import time
-from bb.cooker import BBCooker
-from multiprocessing import Event, Process, util
+from Queue import Empty
+from multiprocessing import Event, Process, util, Queue, Pipe, queues
logger = logging.getLogger('BitBake')
@@ -72,13 +72,11 @@ class ProcessServer(Process):
profile_filename = "profile.log"
profile_processed_filename = "profile.log.processed"
- def __init__(self, command_channel, event_queue, configuration):
+ def __init__(self, command_channel, event_queue):
Process.__init__(self)
self.command_channel = command_channel
self.event_queue = event_queue
self.event = EventAdapter(event_queue)
- self.configuration = configuration
- self.cooker = BBCooker(configuration, self.register_idle_function)
self._idlefunctions = {}
self.event_handle = bb.event.register_UIHhandler(self)
self.quit = False
@@ -95,33 +93,7 @@ class ProcessServer(Process):
self._idlefunctions[function] = data
def run(self):
- if self.configuration.profile:
- return self.profile_main()
- else:
- return self.main()
-
- def profile_main(self):
- import cProfile
- profiler = cProfile.Profile()
- try:
- return profiler.runcall(self.main)
- finally:
- profiler.dump_stats(self.profile_filename)
- self.write_profile_stats()
- sys.__stderr__.write("Raw profiling information saved to %s and "
- "processed statistics to %s\n" %
- (self.profile_filename,
- self.profile_processed_filename))
-
- def write_profile_stats(self):
- import pstats
- with open(self.profile_processed_filename, 'w') as outfile:
- stats = pstats.Stats(self.profile_filename, stream=outfile)
- stats.sort_stats('time')
- stats.print_stats()
- stats.print_callers()
- stats.sort_stats('cumulative')
- stats.print_stats()
+ bb.cooker.server_main(self.cooker, self.main)
def main(self):
# Ignore SIGINT within the server, as all SIGINT handling is done by
@@ -219,3 +191,74 @@ class ProcessServer(Process):
# which can result in a bitbake server hang during the parsing process
if (2, 6, 0) <= sys.version_info < (2, 6, 3):
_bootstrap = bootstrap_2_6_6
+
+class BitBakeServerConnection():
+ def __init__(self, server):
+ self.server = server
+ self.procserver = server.server
+ self.connection = ServerCommunicator(server.ui_channel)
+ self.events = server.event_queue
+
+ def terminate(self, force = False):
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
+ self.procserver.stop()
+ if force:
+ self.procserver.join(0.5)
+ if self.procserver.is_alive():
+ self.procserver.terminate()
+ self.procserver.join()
+ else:
+ self.procserver.join()
+ while True:
+ try:
+ event = self.server.event_queue.get(block=False)
+ except (Empty, IOError):
+ break
+ if isinstance(event, logging.LogRecord):
+ logger.handle(event)
+ self.server.ui_channel.close()
+ self.server.event_queue.close()
+ if force:
+ sys.exit(1)
+
+# Wrap Queue to provide API which isn't server implementation specific
+class ProcessEventQueue(multiprocessing.queues.Queue):
+ def waitEvent(self, timeout):
+ try:
+ return self.get(True, timeout)
+ except Empty:
+ return None
+
+class BitBakeServer(object):
+ def initServer(self):
+ # establish communication channels. We use bidirectional pipes for
+ # ui <--> server command/response pairs
+ # and a queue for server -> ui event notifications
+ #
+ self.ui_channel, self.server_channel = Pipe()
+ self.event_queue = ProcessEventQueue(0)
+
+ self.server = ProcessServer(self.server_channel, self.event_queue)
+
+ def addcooker(self, cooker):
+ self.cooker = cooker
+ self.server.cooker = cooker
+
+ def getServerIdleCB(self):
+ return self.server.register_idle_function
+
+ def saveConnectionDetails(self):
+ return
+
+ def detach(self, cooker_logfile):
+ self.server.start()
+ return
+
+ def establishConnection(self):
+ self.connection = BitBakeServerConnection(self)
+ signal.signal(signal.SIGTERM, lambda i, s: self.connection.terminate(force=True))
+ return self.connection
+
+ def launchUI(self, uifunc, *args):
+ return bb.cooker.server_main(self.cooker, uifunc, *args)
+
OpenPOWER on IntegriCloud