-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Labels
Description
When using multiple threads -- each with its own channel -- I run into a threadlock during calls to basic_get. The following code should quickly yield a threadlock. I suspect that it's because basic_get is using the channel's lock instead of a shared lock from the connection.
import logging
import threading
from threading import Thread
from amqpy import Connection
log = logging.getLogger('threadlock')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)
def read(connection):
thread_name = threading.current_thread().getName()
exchange_id = 'amqp.topic'
queue_id = 'test.queue.{}'.format(thread_name)
routing_key = queue_id
log.debug('Starting {}'.format(thread_name))
channel = connection.channel()
channel.exchange_declare(exchange_id, 'topic', durable=True, auto_delete=False)
channel.queue_declare(queue_id)
channel.queue_bind(queue_id, exchange=exchange_id, routing_key=routing_key)
read_count = 0
while True:
messages = (channel.basic_get() for _ in range(1))
for _ in messages:
read_count += 1
log.debug('{}::{}'.format(thread_name, read_count))
def main():
connection = Connection()
for _ in range(25):
t = Thread(target=read, args=(connection,))
t.start()
while True:
pass
if __name__ == '__main__':
main()