{"action":"created","issue":{"url":"https://api.github.com/repos/veegee/amqpy/issues/29","repository_url":"https://api.github.com/repos/veegee/amqpy","labels_url":"https://api.github.com/repos/veegee/amqpy/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/veegee/amqpy/issues/29/comments","events_url":"https://api.github.com/repos/veegee/amqpy/issues/29/events","html_url":"https://github.com/veegee/amqpy/issues/29","id":156131715,"number":29,"title":"threadlock with basic_get","user":{"login":"pryano","id":5275564,"avatar_url":"https://avatars.githubusercontent.com/u/5275564?v=3","gravatar_id":"","url":"https://api.github.com/users/pryano","html_url":"https://github.com/pryano","followers_url":"https://api.github.com/users/pryano/followers","following_url":"https://api.github.com/users/pryano/following{/other_user}","gists_url":"https://api.github.com/users/pryano/gists{/gist_id}","starred_url":"https://api.github.com/users/pryano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pryano/subscriptions","organizations_url":"https://api.github.com/users/pryano/orgs","repos_url":"https://api.github.com/users/pryano/repos","events_url":"https://api.github.com/users/pryano/events{/privacy}","received_events_url":"https://api.github.com/users/pryano/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-22T02:43:55Z","updated_at":"2016-05-22T03:10:44Z","closed_at":null,"body":"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.\r\n\r\n```python\r\nimport logging\r\nimport threading\r\nfrom threading import Thread\r\n\r\nfrom amqpy import Connection\r\n\r\nlog = logging.getLogger('threadlock')\r\nlog.addHandler(logging.StreamHandler())\r\nlog.setLevel(logging.DEBUG)\r\n\r\n\r\ndef read(connection):\r\n    thread_name = threading.current_thread().getName()\r\n    exchange_id = 'amqp.topic'\r\n    queue_id = 'test.queue.{}'.format(thread_name)\r\n    routing_key = queue_id\r\n\r\n    log.debug('Starting {}'.format(thread_name))\r\n\r\n    channel = connection.channel()\r\n    channel.exchange_declare(exchange_id, 'topic', durable=True, auto_delete=False)\r\n    channel.queue_declare(queue_id)\r\n    channel.queue_bind(queue_id, exchange=exchange_id, routing_key=routing_key)\r\n\r\n    read_count = 0\r\n    while True:\r\n        messages = (channel.basic_get() for _ in range(1))\r\n        for _ in messages:\r\n            read_count += 1\r\n            log.debug('{}::{}'.format(thread_name, read_count))\r\n\r\n\r\ndef main():\r\n    connection = Connection()\r\n\r\n    for _ in range(25):\r\n        t = Thread(target=read, args=(connection,))\r\n        t.start()\r\n\r\n    while True:\r\n        pass\r\n\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n```"},"comment":{"url":"https://api.github.com/repos/veegee/amqpy/issues/comments/220811898","html_url":"https://github.com/veegee/amqpy/issues/29#issuecomment-220811898","issue_url":"https://api.github.com/repos/veegee/amqpy/issues/29","id":220811898,"user":{"login":"veegee","id":1820417,"avatar_url":"https://avatars.githubusercontent.com/u/1820417?v=3","gravatar_id":"","url":"https://api.github.com/users/veegee","html_url":"https://github.com/veegee","followers_url":"https://api.github.com/users/veegee/followers","following_url":"https://api.github.com/users/veegee/following{/other_user}","gists_url":"https://api.github.com/users/veegee/gists{/gist_id}","starred_url":"https://api.github.com/users/veegee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/veegee/subscriptions","organizations_url":"https://api.github.com/users/veegee/orgs","repos_url":"https://api.github.com/users/veegee/repos","events_url":"https://api.github.com/users/veegee/events{/privacy}","received_events_url":"https://api.github.com/users/veegee/received_events","type":"User","site_admin":false},"created_at":"2016-05-22T03:10:44Z","updated_at":"2016-05-22T03:10:44Z","body":"This is also a common mistake that AMQP beginners make. The right way to consume messages in a channel is by declaring a consumer as opposed to blocking inside a while loop with calls to `basic_get`. \r\n\r\nHowever, if it is indeed causing a deadlock, that looks like a bug in the library. I'll take a look at this soon."}}
{"actor":{"display_login":"veegee"}}