Skip to content

Commit

Permalink
Merge "Create ZeroMQ Context per socket"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Nov 19, 2014
2 parents d9b919f + 0d49793 commit c818803
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions oslo/messaging/_drivers/impl_zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@

CONF = cfg.CONF

ZMQ_CTX = None # ZeroMQ Context, must be global.
matchmaker = None # memoized matchmaker object


Expand Down Expand Up @@ -119,7 +118,8 @@ class ZmqSocket(object):
"""

def __init__(self, addr, zmq_type, bind=True, subscribe=None):
self.sock = _get_ctxt().socket(zmq_type)
self.ctxt = zmq.Context(CONF.rpc_zmq_contexts)
self.sock = self.ctxt.socket(zmq_type)
self.addr = addr
self.type = zmq_type
self.subscriptions = []
Expand Down Expand Up @@ -196,6 +196,7 @@ def close(self):
try:
# Default is to linger
self.sock.close()
self.ctxt.term()
except Exception:
# While this is a bad thing to happen,
# it would be much worse if some of the code calling this
Expand Down Expand Up @@ -759,27 +760,6 @@ def _multi_send(method, context, topic, msg, timeout=None,
return return_val


def cleanup():
"""Clean up resources in use by implementation."""
global ZMQ_CTX
if ZMQ_CTX:
ZMQ_CTX.term()
ZMQ_CTX = None

global matchmaker
matchmaker = None


def _get_ctxt():
if not zmq:
raise ImportError("Failed to import eventlet.green.zmq")

global ZMQ_CTX
if not ZMQ_CTX:
ZMQ_CTX = zmq.Context(CONF.rpc_zmq_contexts)
return ZMQ_CTX


def _get_matchmaker(*args, **kwargs):
global matchmaker
if not matchmaker:
Expand Down Expand Up @@ -858,6 +838,8 @@ class ZmqDriver(base.BaseDriver):

def __init__(self, conf, url, default_exchange=None,
allowed_remote_exmods=None):
if not zmq:
raise ImportError("Failed to import eventlet.green.zmq")
conf.register_opts(zmq_opts)
conf.register_opts(impl_eventlet._eventlet_opts)

Expand Down Expand Up @@ -954,4 +936,4 @@ def listen_for_notifications(self, targets_and_priorities):
return listener

def cleanup(self):
cleanup()
pass

0 comments on commit c818803

Please sign in to comment.