and this time add comments to explain the intention.

Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
 ryu/controller/controller.py | 9 +++++++++
 ryu/lib/hub.py               | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py
index 4d0ccdf..7fe5ac9 100644
--- a/ryu/controller/controller.py
+++ b/ryu/controller/controller.py
@@ -196,7 +196,16 @@ class Datapath(object):
                 buf = self.send_q.get()
                 self.socket.sendall(buf)
         finally:
+            q = self.send_q
+            # first, clear self.send_q to prevent new references.
             self.send_q = None
+            # there might be threads currently blocking in send_q.put().
+            # unblock them by draining the queue.
+            try:
+                while q.get(block=False):
+                    pass
+            except hub.QueueEmpty:
+                pass
 
     def send(self, buf):
         if self.send_q:
diff --git a/ryu/lib/hub.py b/ryu/lib/hub.py
index 2709b63..056ba7d 100644
--- a/ryu/lib/hub.py
+++ b/ryu/lib/hub.py
@@ -37,6 +37,7 @@ if HUB_TYPE == 'gevent':
     kill = gevent.kill
     joinall = gevent.joinall
     Queue = gevent.queue.Queue
+    QueueEmpty = gevent.queue.Empty
     StreamServer = gevent.server.StreamServer
     WSGIServer = gevent.pywsgi.WSGIServer
     Timeout = gevent.Timeout
@@ -74,6 +75,7 @@ elif HUB_TYPE == 'eventlet':
                 pass
 
     Queue = eventlet.queue.Queue
+    QueueEmpty = eventlet.queue.Empty
 
     class StreamServer(object):
         def __init__(self, listen_info, handle=None, backlog=None,
-- 
1.8.0.1


------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to