{"action":"created","issue":{"url":"https://api.github.com/repos/benjamin-hodgson/asynqp/issues/34","labels_url":"https://api.github.com/repos/benjamin-hodgson/asynqp/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/benjamin-hodgson/asynqp/issues/34/comments","events_url":"https://api.github.com/repos/benjamin-hodgson/asynqp/issues/34/events","html_url":"https://github.com/benjamin-hodgson/asynqp/issues/34","id":105575427,"number":34,"title":"Can't handle ConnectionLost when used as a Consumer","user":{"login":"TarasLevelUp","id":8791291,"avatar_url":"https://avatars.githubusercontent.com/u/8791291?v=3","gravatar_id":"","url":"https://api.github.com/users/TarasLevelUp","html_url":"https://github.com/TarasLevelUp","followers_url":"https://api.github.com/users/TarasLevelUp/followers","following_url":"https://api.github.com/users/TarasLevelUp/following{/other_user}","gists_url":"https://api.github.com/users/TarasLevelUp/gists{/gist_id}","starred_url":"https://api.github.com/users/TarasLevelUp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TarasLevelUp/subscriptions","organizations_url":"https://api.github.com/users/TarasLevelUp/orgs","repos_url":"https://api.github.com/users/TarasLevelUp/repos","events_url":"https://api.github.com/users/TarasLevelUp/events{/privacy}","received_events_url":"https://api.github.com/users/TarasLevelUp/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/benjamin-hodgson/asynqp/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-09-09T11:10:36Z","updated_at":"2015-09-15T22:03:53Z","closed_at":null,"body":"Hello, thanks for the great library!\r\nCurrently I am creating a consumer for indexing objects into another DB. It's quite simple, here's the snippet, that illustrates, what I want to do:\r\n```python\r\nimport asyncio\r\nimport asynqp\r\n\r\n\r\n@asyncio.coroutine\r\ndef consumer_coro(queue):\r\n    while True:\r\n        msg = yield from queue.get()\r\n        # Execute indexing here\r\n        print(\"msg received\", msg.body)\r\n        msg.ack()\r\n\r\n\r\n@asyncio.coroutine\r\ndef main_coro():\r\n    # connect to the RabbitMQ broker\r\n    connection = yield from asynqp.connect(\r\n        'localhost', 5672, username='guest', password='guest')\r\n\r\n    # Open a communications channel\r\n    channel = yield from connection.open_channel()\r\n\r\n    # Create a queue and an exchange on the broker\r\n    queue = yield from channel.declare_queue('test.queue')\r\n    event_queue = asyncio.Queue()\r\n    consumer = yield from queue.consume(event_queue.put_nowait)\r\n\r\n    try:\r\n        yield from consumer_coro(event_queue)\r\n    except asyncio.CancelledError:\r\n        pass\r\n    finally:\r\n        # Maybe we got KeyboardInterupt? Try to gracefully close everything\r\n        yield from consumer.cancel()\r\n        yield from channel.close()\r\n        yield from connection.close()\r\n\r\n\r\ndef main():\r\n    loop = asyncio.get_event_loop()\r\n    main_task = asyncio.async(main_coro())\r\n    try:\r\n        loop.run_forever()\r\n    except KeyboardInterrupt:\r\n        main_task.cancel()\r\n        loop.run_until_complete(main_task)\r\n\r\nif __name__ == \"__main__\":\r\n    main()\r\n```\r\n\r\nThe problem is, that when connection is lost I have no way to see it except of the log:\r\n```python\r\nException in callback _SelectorTransport._call_connection_lost(None)\r\nhandle: <Handle _SelectorTransport._call_connection_lost(None)>\r\nTraceback (most recent call last):\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/events.py\", line 120, in _run\r\n    self._callback(*self._args)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/selector_events.py\", line 609, in _call_connection_lost\r\n    self._protocol.connection_lost(exc)\r\n  File \"/Users/taras/workspace/vortex_tests/.env/lib/python3.4/site-packages/asynqp/protocol.py\", line 53, in connection_lost\r\n    raise ConnectionClosedError('The connection was closed')\r\nasynqp.exceptions.ConnectionClosedError: The connection was closed\r\n```"},"comment":{"url":"https://api.github.com/repos/benjamin-hodgson/asynqp/issues/comments/140559672","html_url":"https://github.com/benjamin-hodgson/asynqp/issues/34#issuecomment-140559672","issue_url":"https://api.github.com/repos/benjamin-hodgson/asynqp/issues/34","id":140559672,"user":{"login":"benjamin-hodgson","id":3857587,"avatar_url":"https://avatars.githubusercontent.com/u/3857587?v=3","gravatar_id":"","url":"https://api.github.com/users/benjamin-hodgson","html_url":"https://github.com/benjamin-hodgson","followers_url":"https://api.github.com/users/benjamin-hodgson/followers","following_url":"https://api.github.com/users/benjamin-hodgson/following{/other_user}","gists_url":"https://api.github.com/users/benjamin-hodgson/gists{/gist_id}","starred_url":"https://api.github.com/users/benjamin-hodgson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjamin-hodgson/subscriptions","organizations_url":"https://api.github.com/users/benjamin-hodgson/orgs","repos_url":"https://api.github.com/users/benjamin-hodgson/repos","events_url":"https://api.github.com/users/benjamin-hodgson/events{/privacy}","received_events_url":"https://api.github.com/users/benjamin-hodgson/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T22:03:53Z","updated_at":"2015-09-15T22:03:53Z","body":"@TarasLevelUp Does the API defined in [the docstring in my latest commit](https://github.com/benjamin-hodgson/asynqp/commit/e30c0fda292e5b2a55c685828d525c4fcd5cee26#diff-9721c3d151f1390e070a4e59a1659be1R84) look like what you had in mind?"}}