summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2015-09-16 16:23:50 +0200
committerRuben Pollan <meskio@sindominio.net>2015-09-18 00:14:10 +0200
commit10f6f5b17e0ac1d5d4b433a428efc1beffd999a7 (patch)
treea9b12a600aabd7bb7e95078ebfc2ffdddafa06e6
parent26dc74bcc9afbe45d6082e95a3a72cda16d2941b (diff)
[feat] remove taskthread dependency
Refactor ivan's code (aa4b684d0682ff9faf1577653fa5ceabbc6e0f20) to remove the time.sleep. - Resolves: #7414
-rw-r--r--changes/feature-7414_remove-taskthread-dependency1
-rw-r--r--pkg/requirements.pip1
-rw-r--r--src/leap/bitmask/backend/backend_proxy.py21
3 files changed, 15 insertions, 8 deletions
diff --git a/changes/feature-7414_remove-taskthread-dependency b/changes/feature-7414_remove-taskthread-dependency
new file mode 100644
index 00000000..e209e80f
--- /dev/null
+++ b/changes/feature-7414_remove-taskthread-dependency
@@ -0,0 +1 @@
+o Remove taskthread dependency, replace with custom (and small) code. Closes #7414.
diff --git a/pkg/requirements.pip b/pkg/requirements.pip
index 44915e9d..a5d9f2a0 100644
--- a/pkg/requirements.pip
+++ b/pkg/requirements.pip
@@ -27,5 +27,4 @@ txzmq
# Remove this when u1db fixes its dependency on oauth
oauth
-taskthread
logbook>=0.7.0
diff --git a/src/leap/bitmask/backend/backend_proxy.py b/src/leap/bitmask/backend/backend_proxy.py
index 30b7c5d1..ae300b32 100644
--- a/src/leap/bitmask/backend/backend_proxy.py
+++ b/src/leap/bitmask/backend/backend_proxy.py
@@ -27,8 +27,6 @@ import zmq
from zmq.eventloop import ioloop
from zmq.eventloop import zmqstream
-from taskthread import TimerTask
-
from leap.bitmask.backend.api import API, STOP_REQUEST, PING_REQUEST
from leap.bitmask.backend.settings import Settings
from leap.bitmask.backend.utils import generate_zmq_certificates_if_needed
@@ -141,7 +139,8 @@ class BackendProxy(object):
self._do_work = threading.Event()
self._work_lock = threading.Lock()
self._connection = ZmqREQConnection(self.SERVER, self._set_online)
- self._heartbeat = TimerTask(self._ping, delay=self.PING_INTERVAL)
+ self._heartbeat = threading.Timer(self.PING_INTERVAL,
+ self._heartbeat_loop)
self._ping_event = threading.Event()
self.online = False
self.settings = Settings()
@@ -197,17 +196,25 @@ class BackendProxy(object):
"""
with self._work_lock: # avoid sending after connection was closed
self._do_work.clear()
- self._heartbeat.stop()
+ self._heartbeat.cancel()
self._connection.stop()
logger.debug("BackendProxy worker stopped.")
- def _ping(self):
+ def _heartbeat_loop(self):
"""
- Heartbeat helper.
- Sends a PING request just to know that the server is alive.
+ Sends a PING request every PING_INTERVAL just to know that the server
+ is alive.
"""
self._send_request(PING_REQUEST)
+ # lets acquire the lock to prevent heartbeat timer to get cancel while
+ # we set a new one
+ with self._work_lock:
+ if self._do_work.is_set():
+ self._heartbeat = threading.Timer(self.PING_INTERVAL,
+ self._heartbeat_loop)
+ self._heartbeat.start()
+
def _api_call(self, *args, **kwargs):
"""
Call the `api_method` method in backend (through zmq).