diff options
author | gord chung <gord@live.ca> | 2017-04-13 08:20:07 -0400 |
---|---|---|
committer | Asif Saifuddin Auvi <auvipy@users.noreply.github.com> | 2017-04-13 18:20:07 +0600 |
commit | b66bdcbff98047819359b64648f6ba3f7e2cdcd0 (patch) | |
tree | b8a4aa8f36058dd0bffb517e6bf8db6d7329c956 | |
parent | 469a00df9b2e835d21b9453561a610e2d41a5261 (diff) | |
download | py-amqp-b66bdcbff98047819359b64648f6ba3f7e2cdcd0.tar.gz |
don't fail if collect already called (#128)
avoid AttributeError if collect is called and no channels exist.
can occur if collect called twice.
-rw-r--r-- | amqp/connection.py | 3 | ||||
-rw-r--r-- | t/unit/test_connection.py | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/amqp/connection.py b/amqp/connection.py index e7312c5..d25306b 100644 --- a/amqp/connection.py +++ b/amqp/connection.py @@ -437,7 +437,8 @@ class Connection(AbstractChannel): if self._transport: self._transport.close() - temp_list = [x for x in values(self.channels) if x is not self] + temp_list = [x for x in values(self.channels or {}) + if x is not self] for ch in temp_list: ch.collect() except socket.error: diff --git a/t/unit/test_connection.py b/t/unit/test_connection.py index 11b8521..3a94475 100644 --- a/t/unit/test_connection.py +++ b/t/unit/test_connection.py @@ -232,6 +232,11 @@ class test_Connection: self.conn.collect() assert not self.conn.connect.called + def test_collect_again(self): + self.conn = Connection() + self.conn.collect() + self.conn.collect() + def test_get_free_channel_id__raises_IndexError(self): self.conn._avail_channel_ids = [] with pytest.raises(ResourceError): |