summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-01-16 20:03:11 -0400
committerIvan Alejandro <ivanalejandro0@gmail.com>2015-01-28 18:08:02 -0300
commit928850d8850dbf6631d3e9472387ffa798b5d2af (patch)
tree81f8d2bce987f52372ba40b65791d74192842000
parent3636888834d80a4cba6a096847e031649905e381 (diff)
remove use of threading.Condition
we should deal with this with pure deferreds
-rw-r--r--src/leap/bitmask/backend/components.py13
-rw-r--r--src/leap/bitmask/services/mail/imapcontroller.py17
2 files changed, 13 insertions, 17 deletions
diff --git a/src/leap/bitmask/backend/components.py b/src/leap/bitmask/backend/components.py
index 8ed43364..2ae796f6 100644
--- a/src/leap/bitmask/backend/components.py
+++ b/src/leap/bitmask/backend/components.py
@@ -17,13 +17,16 @@
"""
Backend components
"""
+
+# TODO [ ] Get rid of all this deferToThread mess, or at least contain
+# all of it into its own threadpool.
+
import logging
import os
import socket
import time
from functools import partial
-from threading import Condition
from twisted.internet import threads, defer
from twisted.python import log
@@ -1038,12 +1041,10 @@ class Mail(object):
"""
Stop imap and wait until the service is stopped to signal that is done.
"""
- cv = Condition()
- cv.acquire()
- threads.deferToThread(self._imap_controller.stop_imap_service, cv)
+ # FIXME just get a fucking deferred and signal as a callback, with
+ # timeout and cancellability
+ threads.deferToThread(self._imap_controller.stop_imap_service)
logger.debug('Waiting for imap service to stop.')
- cv.wait(self.SERVICE_STOP_TIMEOUT)
- logger.debug('IMAP stopped')
self._signaler.signal(self._signaler.imap_stopped)
def stop_imap_service(self):
diff --git a/src/leap/bitmask/services/mail/imapcontroller.py b/src/leap/bitmask/services/mail/imapcontroller.py
index bb9eb9dc..1b39ef91 100644
--- a/src/leap/bitmask/services/mail/imapcontroller.py
+++ b/src/leap/bitmask/services/mail/imapcontroller.py
@@ -84,16 +84,16 @@ class IMAPController(object):
d.addCallback(assign_incoming_service)
d.addErrback(lambda f: logger.error(f.printTraceback()))
- def stop_imap_service(self, cv):
+ def stop_imap_service(self):
"""
Stop IMAP service (fetcher, factory and port).
-
- :param cv: A condition variable to which we can signal when imap
- indeed stops.
- :type cv: threading.Condition
"""
if self.incoming_mail_service is not None:
# Stop the loop call in the fetcher
+
+ # XXX BUG -- the deletion of the reference should be made
+ # after stopService() triggers its deferred (ie, cleanup has been
+ # made)
self.incoming_mail_service.stopService()
self.incoming_mail_service = None
@@ -103,12 +103,7 @@ class IMAPController(object):
# Stop the protocol
self.imap_factory.theAccount.closed = True
- self.imap_factory.doStop(cv)
- else:
- # Release the condition variable so the caller doesn't have to wait
- cv.acquire()
- cv.notify()
- cv.release()
+ self.imap_factory.doStop()
def fetch_incoming_mail(self):
"""