From 4a402dff8ef61f7437899a309555d3429e97d92c Mon Sep 17 00:00:00 2001 From: "Bo-Chun Louis Chen(VM)" <louistw@uab.edu> Date: Mon, 23 Mar 2020 19:28:08 +0000 Subject: [PATCH] Remove disconnect call from publish and consume user should explicitly call disconnect Modify README regarding explicity disconnect call --- README.md | 3 +++ rc_rmq.py | 6 +----- rc_util.py | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index df42096..eb8ce91 100644 --- a/README.md +++ b/README.md @@ -44,4 +44,7 @@ rc_rmq.start_consume({ 'cb': callback_function }) + +# don't forget to close connection +rc_rmq.disconnect() ``` diff --git a/rc_rmq.py b/rc_rmq.py index 42e4913..788387c 100644 --- a/rc_rmq.py +++ b/rc_rmq.py @@ -74,6 +74,7 @@ class RCRMQ(object): def disconnect(self): self._channel.close() self._connection.close() + self._connection = None def delete_queue(self): self._channel.queue_delete(self.QUEUE) @@ -89,9 +90,6 @@ class RCRMQ(object): routing_key=self.ROUTING_KEY, body=json.dumps(obj['msg'])) - if not self._consuming: - self.disconnect() - def start_consume(self, obj): if 'queue' in obj: self.QUEUE = obj['queue'] @@ -112,7 +110,5 @@ class RCRMQ(object): except KeyboardInterrupt: self._channel.stop_consuming() - self.disconnect() - def stop_consume(self): self._channel.basic_cancel(self._consumer_tag) diff --git a/rc_util.py b/rc_util.py index a353686..4281437 100644 --- a/rc_util.py +++ b/rc_util.py @@ -13,6 +13,7 @@ def add_account(username, full='', reason=''): "reason": reason } }) + rc_rmq.disconnect() def worker(ch, method, properties, body): msg = json.loads(body) @@ -39,5 +40,6 @@ def consume(username, callback=worker, debug=False): 'routing_key': 'confirm.' + username, 'cb': callback }) + rc_rmq.disconnect() return { 'success' : True } -- GitLab