diff options
author | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2007-10-31 17:44:36 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2007-10-31 17:44:36 (GMT) |
commit | fa80f025af60f733aeb6a0ad8c638779369d7daf (patch) | |
tree | faeb940c1e91eab5649c17a602463517d3af3b8e | |
parent | f0753fadc877dc8408db6c7d5d54d9ffbc171b75 (diff) |
#4083: Remove the active loop and initialize threads.
-rw-r--r-- | NEWS | 1 | ||||
-rwxr-xr-x | bin/datastore-service | 29 |
2 files changed, 12 insertions, 18 deletions
@@ -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() |