From fa80f025af60f733aeb6a0ad8c638779369d7daf Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Wed, 31 Oct 2007 17:44:36 +0000 Subject: #4083: Remove the active loop and initialize threads. --- diff --git a/NEWS b/NEWS index 098a22f..5fcb908 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ +* #4083: Remove the active loop and initialize threads. (tomeu) * #4182: Flush every 20 changes or 1 minute after the last unflushed change. (tomeu) Snapshot 5051fc3a4b diff --git a/bin/datastore-service b/bin/datastore-service index 140f494..693c736 100755 --- a/bin/datastore-service +++ b/bin/datastore-service @@ -3,9 +3,13 @@ import sys, os, signal, logging import gobject import dbus.service import dbus.mainloop.glib +import dbus.glib from olpc.datastore import DataStore, backingstore from sugar import logger +gobject.threads_init() +dbus.glib.threads_init() + # Path handling profile = os.environ.get('SUGAR_PROFILE', 'default') base_dir = os.path.join(os.path.expanduser('~'), '.sugar', profile) @@ -46,12 +50,13 @@ logging.info("Starting Datastore %s" % (repo_dir)) mainloop = gobject.MainLoop() def handle_disconnect(): - global connected - connected = False + global mainloop + mainloop.quit() + logging.debug("Datastore disconnected from the bus.") def handle_shutdown(signum, frame): - global connected - connected = False + global mainloop + mainloop.quit() raise SystemExit("Shutting down on signal %s" % signum) bus.set_exit_on_disconnect(False) @@ -63,29 +68,17 @@ signal.signal(signal.SIGHUP, handle_shutdown) signal.signal(signal.SIGTERM, handle_shutdown) def main(): - # XXX: The context/sleep loop is a work around for what seems - # to be the mainloop blocking in such a way that the indexer - # thread doesn't run until new dbus messages come in... - # I intend to track this down post trial-2 - # really awful - import time - context = mainloop.get_context() - if '-m' in sys.argv: # mount automatically for local testing ds.mount(repo_dir) ds.complete_indexing() try: - while connected: - context.iteration(False) - time.sleep(0.0025) - + mainloop.run() except KeyboardInterrupt: logging.info("DataStore shutdown by user") except: - logging.debug("Datastore shutdown with error", - exc_info=sys.exc_info()) + logging.error("Datastore shutdown with error", exc_info=sys.exc_info()) main() -- cgit v0.9.1