[ARVADOS] created: dec876f5ea5d88ea9674edc01b86ed2a4fa95078

git at public.curoverse.com git at public.curoverse.com
Wed Nov 18 15:33:49 EST 2015


        at  dec876f5ea5d88ea9674edc01b86ed2a4fa95078 (commit)


commit dec876f5ea5d88ea9674edc01b86ed2a4fa95078
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Wed Nov 18 15:24:02 2015 -0500

    7654: Fix hang in close().

diff --git a/sdk/python/arvados/events.py b/sdk/python/arvados/events.py
index df5b3e7..410463b 100644
--- a/sdk/python/arvados/events.py
+++ b/sdk/python/arvados/events.py
@@ -28,33 +28,24 @@ class EventClient(WebSocketClient):
         super(EventClient, self).__init__(url, ssl_options=ssl_options)
         self.filters = filters
         self.on_event = on_event
-        self.stop = threading.Event()
         self.last_log_id = last_log_id
+        self.closed_lock = threading.Lock()
+        self.closed = False
 
     def opened(self):
         self.subscribe(self.filters, self.last_log_id)
 
     def received_message(self, m):
-        self.on_event(json.loads(str(m)))
-
-    def closed(self, code, reason=None):
-        self.stop.set()
+        with self.closed_lock:
+            if not self.closed:
+                self.on_event(json.loads(str(m)))
 
     def close(self, code=1000, reason=''):
         """Close event client and wait for it to finish."""
-
-        # parent close() method sends a asynchronous "closed" event to the server
         super(EventClient, self).close(code, reason)
-
-        # if server doesn't respond by finishing the close handshake, we'll be
-        # stuck in limbo forever.  We don't need to wait for the server to
-        # respond to go ahead and actually close the socket.
-        self.close_connection()
-
-        # wait for websocket thread to finish up (closed() is called by
-        # websocket thread in as part of terminate())
-        while not self.stop.is_set():
-            self.stop.wait(1)
+        with self.closed_lock:
+            # make sure we don't process any more messages.
+            self.closed = True
 
     def subscribe(self, filters, last_log_id=None):
         m = {"method": "subscribe", "filters": filters}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list