summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsk Solem <ask@celeryproject.org>2013-03-08 10:54:03 +0000
committerAsk Solem <ask@celeryproject.org>2013-03-08 10:54:03 +0000
commit8a789c482460dbfb2bbf34ee227a270d768210f4 (patch)
treef0852d9c6694bdfe474b1009049471697eb94fae
parenta7c39a33a291f860aa32b6e9a57384042b6b746e (diff)
downloadpy-amqp-8a789c482460dbfb2bbf34ee227a270d768210f4.tar.gz
channel(id) should claim id from array of free ids
-rw-r--r--amqp/channel.py5
-rw-r--r--amqp/connection.py7
2 files changed, 11 insertions, 1 deletions
diff --git a/amqp/channel.py b/amqp/channel.py
index a46f931..fa6cd2d 100644
--- a/amqp/channel.py
+++ b/amqp/channel.py
@@ -62,8 +62,11 @@ class Channel(AbstractChannel):
is left as plain bytes.
"""
- if channel_id is None:
+ if channel_id:
+ connection._claim_channel_id(channel_id)
+ else:
channel_id = connection._get_free_channel_id()
+
AMQP_LOGGER.debug('using channel_id: %d', channel_id)
super(Channel, self).__init__(connection, channel_id)
diff --git a/amqp/connection.py b/amqp/connection.py
index ceea7e4..6768513 100644
--- a/amqp/connection.py
+++ b/amqp/connection.py
@@ -173,6 +173,13 @@ class Connection(AbstractChannel):
'No free channel ids, current=%d, channel_max=%d' % (
len(self.channels), self.channel_max), (20, 10))
+ def _claim_channel_id(self, channel_id):
+ try:
+ return self._avail_channel_ids.remove(channel_id)
+ except ValueError:
+ raise ConnectionError(
+ 'Channel %r already open' % (channel_id, ))
+
def _wait_method(self, channel_id, allowed_methods):
"""Wait for a method from the server destined for
a particular channel."""