mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Close zeromq context and socket.
This commit is contained in:
parent
6bbaa26f64
commit
d25ee940c4
1 changed files with 9 additions and 3 deletions
|
@ -43,6 +43,7 @@ class Connection(object):
|
||||||
|
|
||||||
self.host = host
|
self.host = host
|
||||||
self.key = utils.key_for_hostname(host)
|
self.key = utils.key_for_hostname(host)
|
||||||
|
self.context = None
|
||||||
self.socket = None
|
self.socket = None
|
||||||
# port passed in is the SSH port, which we ignore
|
# port passed in is the SSH port, which we ignore
|
||||||
self.port = constants.ZEROMQ_PORT
|
self.port = constants.ZEROMQ_PORT
|
||||||
|
@ -54,8 +55,8 @@ class Connection(object):
|
||||||
raise errors.AnsibleError("zmq is not installed")
|
raise errors.AnsibleError("zmq is not installed")
|
||||||
|
|
||||||
# this is rough/temporary and will likely be optimized later ...
|
# this is rough/temporary and will likely be optimized later ...
|
||||||
context = zmq.Context()
|
self.context = zmq.Context()
|
||||||
socket = context.socket(zmq.REQ)
|
socket = self.context.socket(zmq.REQ)
|
||||||
addr = "tcp://%s:%s" % (self.host, self.port)
|
addr = "tcp://%s:%s" % (self.host, self.port)
|
||||||
socket.connect(addr)
|
socket.connect(addr)
|
||||||
self.socket = socket
|
self.socket = socket
|
||||||
|
@ -125,5 +126,10 @@ class Connection(object):
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
''' terminate the connection '''
|
''' terminate the connection '''
|
||||||
# no need for this
|
# Be a good citizen
|
||||||
|
try:
|
||||||
|
self.socket.close()
|
||||||
|
self.context.term()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue