diff --git a/README.md b/README.md index df4209656d1e0616c589282240d77d7c0b40eeb3..eb8ce910a231ded44263113169838b4b3cac4d77 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 42e49137457f7ffdbe6f3156881a1fceca029ad8..788387c4f00b7828d69c8cc1e0a88159b127900f 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 a3536862f364b9fc6b19e1a95583400bcaa16dc5..4281437cc2222ba66f8723076e76bd05020f9805 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 }