{"action":"created","issue":{"url":"https://api.github.com/repos/aio-libs/aioredis/issues/59","labels_url":"https://api.github.com/repos/aio-libs/aioredis/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/aio-libs/aioredis/issues/59/comments","events_url":"https://api.github.com/repos/aio-libs/aioredis/issues/59/events","html_url":"https://github.com/aio-libs/aioredis/issues/59","id":66158818,"number":59,"title":"When an aioredis coroutine is wrapped in a cancelled task, the pending call is not cancelled","user":{"login":"Natim","id":229453,"avatar_url":"https://avatars.githubusercontent.com/u/229453?v=3","gravatar_id":"","url":"https://api.github.com/users/Natim","html_url":"https://github.com/Natim","followers_url":"https://api.github.com/users/Natim/followers","following_url":"https://api.github.com/users/Natim/following{/other_user}","gists_url":"https://api.github.com/users/Natim/gists{/gist_id}","starred_url":"https://api.github.com/users/Natim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Natim/subscriptions","organizations_url":"https://api.github.com/users/Natim/orgs","repos_url":"https://api.github.com/users/Natim/repos","events_url":"https://api.github.com/users/Natim/events{/privacy}","received_events_url":"https://api.github.com/users/Natim/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aio-libs/aioredis/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-04-03T14:43:35Z","updated_at":"2015-04-08T15:41:48Z","closed_at":null,"body":"When a coroutine is wrapped in a Task that is cancelled, the pending redis call is not cancelled and its result is lost.\r\n\r\nHere is an example using ``BLPOP``\r\n\r\n``` python\r\n#!/usr/bin/env python\r\n\r\nimport asyncio\r\nimport aioredis\r\n\r\n\r\n@asyncio.coroutine\r\ndef simulate_client():\r\n    redis = yield from aioredis.create_redis(('localhost', 6379))\r\n    print(\"$ Client sleeps\")\r\n    yield from asyncio.sleep(2)\r\n    print(\"$ Client add task hello\")\r\n    yield from redis.lpush(\"channel\", \"hello\")\r\n    print(\"$ Client sleeps\")    \r\n    yield from asyncio.sleep(10)\r\n\r\n\r\n@asyncio.coroutine\r\ndef simulate_server():\r\n    redis = yield from aioredis.create_redis(('localhost', 6379))\r\n    print(\"# Wait for task\")\r\n    try:\r\n        data = yield from asyncio.wait_for(redis.blpop(\"channel\"), 1)\r\n    except asyncio.TimeoutError:\r\n        print(\"# BLPOP timed-out\")\r\n        yield from asyncio.sleep(5)\r\n        print(\"# Wait for task\")\r\n        try:\r\n            data = yield from asyncio.wait_for(redis.blpop(\"channel\"), 1)\r\n        except asyncio.TimeoutError:\r\n            print(\"# BLPOP timed-out the task is lost.\")\r\n        else:\r\n            print(\"# BLPOP returned: %s\" % data)\r\n    else:\r\n        print(\"# BLPOP returned: %s\" % data)\r\n\r\n\r\nasyncio.get_event_loop().run_until_complete(\r\n    asyncio.wait({simulate_server(), simulate_client()})\r\n)\r\n```\r\n\r\nFor this example, I can fix it using the timeout value of BLPOP but I have the same behavior when using it with ``asyncio.wait``\r\n\r\n```  python\r\n    yield from asyncio.wait(\r\n                {redis.blpop(\"channel\"), websocket.recv()},\r\n                return_when=asyncio.FIRST_COMPLETED)\r\n```"},"comment":{"url":"https://api.github.com/repos/aio-libs/aioredis/issues/comments/90955271","html_url":"https://github.com/aio-libs/aioredis/issues/59#issuecomment-90955271","issue_url":"https://api.github.com/repos/aio-libs/aioredis/issues/59","id":90955271,"user":{"login":"Natim","id":229453,"avatar_url":"https://avatars.githubusercontent.com/u/229453?v=3","gravatar_id":"","url":"https://api.github.com/users/Natim","html_url":"https://github.com/Natim","followers_url":"https://api.github.com/users/Natim/followers","following_url":"https://api.github.com/users/Natim/following{/other_user}","gists_url":"https://api.github.com/users/Natim/gists{/gist_id}","starred_url":"https://api.github.com/users/Natim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Natim/subscriptions","organizations_url":"https://api.github.com/users/Natim/orgs","repos_url":"https://api.github.com/users/Natim/repos","events_url":"https://api.github.com/users/Natim/events{/privacy}","received_events_url":"https://api.github.com/users/Natim/received_events","type":"User","site_admin":false},"created_at":"2015-04-08T15:41:48Z","updated_at":"2015-04-08T15:41:48Z","body":"Here is how I finally handled the thing, with the pool of connection it is even harder.\r\n\r\nhttps://github.com/mozilla-services/remote-worker-server/pull/9/files#diff-1941b7aa355a66a8168348cce764a718R131\r\n\r\nI'd like to be able to return the future and then do ``fut.cancel()`` but I am not sure of how to do it yet."}}