From 09b71df943e37a59da649d64fee1dff0356a16e8 Mon Sep 17 00:00:00 2001 From: Stavros Sachtouris <saxtouri@admin.grnet.gr> Date: Tue, 16 Jun 2015 13:25:37 +0300 Subject: [PATCH] Remove syncer from SYNCERS dict after shutdown --- agkyra/protocol.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/agkyra/protocol.py b/agkyra/protocol.py index 08a60ff..63c99d0 100644 --- a/agkyra/protocol.py +++ b/agkyra/protocol.py @@ -67,7 +67,6 @@ class SessionHelper(object): self._init_db_relation() # self.session = self._load_active_session() or self._create_session() - # self.db.close() def _init_db_relation(self): @@ -282,15 +281,6 @@ class WebSocketProtocol(WebSocket): return sync_obj return None - def _shutdown(self): - """Shutdown the service""" - LOG.debug('Shutdown syncer') - self.close() - if self.syncer and self.can_sync(): - self.syncer.stop_all_daemons() - LOG.debug('Wait open syncs to complete') - self.syncer.wait_sync_threads() - def clean_db(self): """Clean DB from session traces""" LOG.debug('Remove session traces') @@ -301,6 +291,16 @@ class WebSocketProtocol(WebSocket): db.commit() db.close() + def shutdown_syncer(self, syncer_key=0): + """Shutdown the service""" + LOG.debug('Shutdown syncer') + with SYNCERS.lock() as d: + syncer = d.pop(syncer_key, None) + if syncer and self.can_sync(): + syncer.stop_all_daemons() + LOG.debug('Wait open syncs to complete') + syncer.wait_sync_threads() + def heartbeat(self): """Check if socket should be alive""" db, alive = sqlite3.connect(self.session_db), True @@ -319,7 +319,8 @@ class WebSocketProtocol(WebSocket): except sqlite3.OperationalError: alive = True db.close() - self._shutdown() + self.shutdown_syncer() + self.close() def _get_default_sync(self): """Get global.default_sync or pick the first sync as default -- GitLab