{"action":"created","issue":{"url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3316","repository_url":"https://api.github.com/repos/aio-libs/aiohttp","labels_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3316/labels{/name}","comments_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3316/comments","events_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3316/events","html_url":"https://github.com/aio-libs/aiohttp/issues/3316","id":366402785,"node_id":"MDU6SXNzdWUzNjY0MDI3ODU=","number":3316,"title":"Scheduled tasks in ensure_future are overlapping by the last one","user":{"login":"yutkin","id":2982775,"node_id":"MDQ6VXNlcjI5ODI3NzU=","avatar_url":"https://avatars3.githubusercontent.com/u/2982775?v=4","gravatar_id":"","url":"https://api.github.com/users/yutkin","html_url":"https://github.com/yutkin","followers_url":"https://api.github.com/users/yutkin/followers","following_url":"https://api.github.com/users/yutkin/following{/other_user}","gists_url":"https://api.github.com/users/yutkin/gists{/gist_id}","starred_url":"https://api.github.com/users/yutkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yutkin/subscriptions","organizations_url":"https://api.github.com/users/yutkin/orgs","repos_url":"https://api.github.com/users/yutkin/repos","events_url":"https://api.github.com/users/yutkin/events{/privacy}","received_events_url":"https://api.github.com/users/yutkin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-10-03T15:40:25Z","updated_at":"2018-10-03T15:54:26Z","closed_at":null,"author_association":"NONE","body":"Hello! \r\n\r\nI'm trying to add a new handler that use another existing handler for processing multiple requests at once:\r\n\r\n```\r\nasync def process_multiple_queries(request):\r\n    init_request = request.clone()\r\n    body = await request.json()\r\n\r\n    for query in body[\"queries\"]:\r\n\r\n        @asyncio.coroutine\r\n        def fake_json(self):\r\n            return query\r\n\r\n        # Replace request body on new fake json\r\n        R = init_request.clone()\r\n        R.json = fake_json.__get__(R, Request)\r\n\r\n        # Process request in the background task\r\n        asyncio.ensure_future(process_query(R))\r\n\r\nasync def process_query(request):\r\n    body = await request.json()\r\n    # ... Process body ...\r\n    return web.json_response({\"result\": \"OK\"})\r\n\r\n```\r\nHowever, results of all scheduled tasks are equal to the result of the last task, i.e. bodies of all requests that passed to `process_query` are equal to the body of the last scheduled request.\r\n\r\nBut if I add `asyncio.sleep(5)` after `asyncio.ensure_future(process_query(R))`, all tasks are processed properly and produce different results.\r\n\r\nPython 3.6 in Docker CentOS 7."},"comment":{"url":"https://api.github.com/repos/aio-libs/aiohttp/issues/comments/426690729","html_url":"https://github.com/aio-libs/aiohttp/issues/3316#issuecomment-426690729","issue_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3316","id":426690729,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNjY5MDcyOQ==","user":{"login":"yutkin","id":2982775,"node_id":"MDQ6VXNlcjI5ODI3NzU=","avatar_url":"https://avatars3.githubusercontent.com/u/2982775?v=4","gravatar_id":"","url":"https://api.github.com/users/yutkin","html_url":"https://github.com/yutkin","followers_url":"https://api.github.com/users/yutkin/followers","following_url":"https://api.github.com/users/yutkin/following{/other_user}","gists_url":"https://api.github.com/users/yutkin/gists{/gist_id}","starred_url":"https://api.github.com/users/yutkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yutkin/subscriptions","organizations_url":"https://api.github.com/users/yutkin/orgs","repos_url":"https://api.github.com/users/yutkin/repos","events_url":"https://api.github.com/users/yutkin/events{/privacy}","received_events_url":"https://api.github.com/users/yutkin/received_events","type":"User","site_admin":false},"created_at":"2018-10-03T15:54:26Z","updated_at":"2018-10-03T15:54:26Z","author_association":"NONE","body":"OK. Thank you."}}
{"actor":{"display_login":"yutkin"}}