{"action":"created","comment":{"url":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/comments/75957079","id":75957079,"diff_hunk":"@@ -0,0 +1,62 @@\n+#!/usr/bin/env python3\n+\"\"\"Example of aiohttp.web.Application.on_startup signal handler\"\"\"\n+import aioredis\n+import asyncio\n+from aiohttp.web import Application, run_app, WebSocketResponse\n+\n+async def websocket_handler(request):\n+    ws = WebSocketResponse()\n+    await ws.prepare(request)\n+    request.app['websockets'].append(ws)\n+    try:\n+        async for msg in ws:\n+            print(msg)\n+            await asyncio.sleep(1)\n+    finally:\n+        request.app['websockets'].remove(ws)\n+    return ws\n+\n+\n+async def on_shutdown(app):\n+    for ws in app['websockets']:\n+        await ws.close(code=999, message='Server shutdown')\n+\n+\n+async def listen_to_redis(app):\n+    try:\n+        sub = await aioredis.create_redis(('localhost', 6379), loop=app.loop)\n+        ch, *_ = await sub.subscribe('news')\n+        async for msg in ch.iter(encoding='utf-8'):\n+            # Forward message to all connected websockets:\n+            for ws in app['websockets']:\n+                ws.send_str('{}: {}'.format(ch.name, msg))\n+            print(\"message in {}: {}\".format(ch.name, msg))\n+    except asyncio.CancelledError:","path":"examples/background_tasks.py","position":34,"original_position":34,"commit_id":"50f6d93abeffd8bf3ab596026287a21a54b1dbf1","original_commit_id":"50f6d93abeffd8bf3ab596026287a21a54b1dbf1","user":{"login":"asvetlov","id":356399,"avatar_url":"https://avatars.githubusercontent.com/u/356399?v=3","gravatar_id":"","url":"https://api.github.com/users/asvetlov","html_url":"https://github.com/asvetlov","followers_url":"https://api.github.com/users/asvetlov/followers","following_url":"https://api.github.com/users/asvetlov/following{/other_user}","gists_url":"https://api.github.com/users/asvetlov/gists{/gist_id}","starred_url":"https://api.github.com/users/asvetlov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asvetlov/subscriptions","organizations_url":"https://api.github.com/users/asvetlov/orgs","repos_url":"https://api.github.com/users/asvetlov/repos","events_url":"https://api.github.com/users/asvetlov/events{/privacy}","received_events_url":"https://api.github.com/users/asvetlov/received_events","type":"User","site_admin":false},"body":"`finally` is better than `except CancelledError`.\r\nWe should close redis subscription unconditionally.","created_at":"2016-08-23T21:42:41Z","updated_at":"2016-08-23T21:42:41Z","html_url":"https://github.com/KeepSafe/aiohttp/pull/1107#discussion_r75957079","pull_request_url":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/1107","_links":{"self":{"href":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/comments/75957079"},"html":{"href":"https://github.com/KeepSafe/aiohttp/pull/1107#discussion_r75957079"},"pull_request":{"href":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/1107"}}},"pull_request":{"url":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/1107","id":82254243,"html_url":"https://github.com/KeepSafe/aiohttp/pull/1107","diff_url":"https://github.com/KeepSafe/aiohttp/pull/1107.diff","patch_url":"https://github.com/KeepSafe/aiohttp/pull/1107.patch","issue_url":"https://api.github.com/repos/KeepSafe/aiohttp/issues/1107","number":1107,"state":"open","locked":false,"title":"#1104 Modify docs for background tasks","user":{"login":"f0t0n","id":957767,"avatar_url":"https://avatars.githubusercontent.com/u/957767?v=3","gravatar_id":"","url":"https://api.github.com/users/f0t0n","html_url":"https://github.com/f0t0n","followers_url":"https://api.github.com/users/f0t0n/followers","following_url":"https://api.github.com/users/f0t0n/following{/other_user}","gists_url":"https://api.github.com/users/f0t0n/gists{/gist_id}","starred_url":"https://api.github.com/users/f0t0n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/f0t0n/subscriptions","organizations_url":"https://api.github.com/users/f0t0n/orgs","repos_url":"https://api.github.com/users/f0t0n/repos","events_url":"https://api.github.com/users/f0t0n/events{/privacy}","received_events_url":"https://api.github.com/users/f0t0n/received_events","type":"User","site_admin":false},"body":"<!-- Thank you for your contribution!\r\n\r\n     Before submit your Pull Request, make sure you picked\r\n     the right branch:\r\n\r\n     - If you propose a new feature or improvement, select \"master\"\r\n       as a target branch;\r\n     - If this is a bug fix or documentation amendment, select\r\n       the latest release branch (which looks like \"0.xx\") -->\r\n\r\n## What do these changes do?\r\n\r\n<!-- Please give a short brief about these changes. -->\r\n\r\nChanges:\r\n\r\n- Modify docs for background tasks\r\n- Add an example code to examples directory\r\n\r\nAs discussed the old code example for background tasks creating was working but not optimal.\r\nRemoved `asyncio.gather()` from the example and used `app.loop.create_task()` instead.\r\nAlso added an example of tasks cancellation on cleanup.\r\n\r\n## Are there changes in behavior for the user?\r\n\r\n<!-- Outline any notable behaviour for the end users. -->\r\nNone\r\n\r\n## Related issue number\r\n\r\n<!-- Are there any issues opened that will be resolved by merging this change? -->\r\n#1104\r\n\r\n## Checklist\r\n\r\n- [x] I think the code is well written\r\n- [x] Unit tests for the changes exist\r\n- [x] Documentation reflects the changes\r\n","created_at":"2016-08-22T20:08:43Z","updated_at":"2016-08-23T21:42:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b5f8162c323b502a6d30a6415c9c339a631e9b1a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/1107/commits","review_comments_url":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/1107/comments","review_comment_url":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/KeepSafe/aiohttp/issues/1107/comments","statuses_url":"https://api.github.com/repos/KeepSafe/aiohttp/statuses/50f6d93abeffd8bf3ab596026287a21a54b1dbf1","head":{"label":"f0t0n:feature/doc-background-tasks","ref":"feature/doc-background-tasks","sha":"50f6d93abeffd8bf3ab596026287a21a54b1dbf1","user":{"login":"f0t0n","id":957767,"avatar_url":"https://avatars.githubusercontent.com/u/957767?v=3","gravatar_id":"","url":"https://api.github.com/users/f0t0n","html_url":"https://github.com/f0t0n","followers_url":"https://api.github.com/users/f0t0n/followers","following_url":"https://api.github.com/users/f0t0n/following{/other_user}","gists_url":"https://api.github.com/users/f0t0n/gists{/gist_id}","starred_url":"https://api.github.com/users/f0t0n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/f0t0n/subscriptions","organizations_url":"https://api.github.com/users/f0t0n/orgs","repos_url":"https://api.github.com/users/f0t0n/repos","events_url":"https://api.github.com/users/f0t0n/events{/privacy}","received_events_url":"https://api.github.com/users/f0t0n/received_events","type":"User","site_admin":false},"repo":{"id":66148133,"name":"aiohttp","full_name":"f0t0n/aiohttp","owner":{"login":"f0t0n","id":957767,"avatar_url":"https://avatars.githubusercontent.com/u/957767?v=3","gravatar_id":"","url":"https://api.github.com/users/f0t0n","html_url":"https://github.com/f0t0n","followers_url":"https://api.github.com/users/f0t0n/followers","following_url":"https://api.github.com/users/f0t0n/following{/other_user}","gists_url":"https://api.github.com/users/f0t0n/gists{/gist_id}","starred_url":"https://api.github.com/users/f0t0n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/f0t0n/subscriptions","organizations_url":"https://api.github.com/users/f0t0n/orgs","repos_url":"https://api.github.com/users/f0t0n/repos","events_url":"https://api.github.com/users/f0t0n/events{/privacy}","received_events_url":"https://api.github.com/users/f0t0n/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/f0t0n/aiohttp","description":"http client/server for asyncio (PEP-3156)","fork":true,"url":"https://api.github.com/repos/f0t0n/aiohttp","forks_url":"https://api.github.com/repos/f0t0n/aiohttp/forks","keys_url":"https://api.github.com/repos/f0t0n/aiohttp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/f0t0n/aiohttp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/f0t0n/aiohttp/teams","hooks_url":"https://api.github.com/repos/f0t0n/aiohttp/hooks","issue_events_url":"https://api.github.com/repos/f0t0n/aiohttp/issues/events{/number}","events_url":"https://api.github.com/repos/f0t0n/aiohttp/events","assignees_url":"https://api.github.com/repos/f0t0n/aiohttp/assignees{/user}","branches_url":"https://api.github.com/repos/f0t0n/aiohttp/branches{/branch}","tags_url":"https://api.github.com/repos/f0t0n/aiohttp/tags","blobs_url":"https://api.github.com/repos/f0t0n/aiohttp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/f0t0n/aiohttp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/f0t0n/aiohttp/git/refs{/sha}","trees_url":"https://api.github.com/repos/f0t0n/aiohttp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/f0t0n/aiohttp/statuses/{sha}","languages_url":"https://api.github.com/repos/f0t0n/aiohttp/languages","stargazers_url":"https://api.github.com/repos/f0t0n/aiohttp/stargazers","contributors_url":"https://api.github.com/repos/f0t0n/aiohttp/contributors","subscribers_url":"https://api.github.com/repos/f0t0n/aiohttp/subscribers","subscription_url":"https://api.github.com/repos/f0t0n/aiohttp/subscription","commits_url":"https://api.github.com/repos/f0t0n/aiohttp/commits{/sha}","git_commits_url":"https://api.github.com/repos/f0t0n/aiohttp/git/commits{/sha}","comments_url":"https://api.github.com/repos/f0t0n/aiohttp/comments{/number}","issue_comment_url":"https://api.github.com/repos/f0t0n/aiohttp/issues/comments{/number}","contents_url":"https://api.github.com/repos/f0t0n/aiohttp/contents/{+path}","compare_url":"https://api.github.com/repos/f0t0n/aiohttp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/f0t0n/aiohttp/merges","archive_url":"https://api.github.com/repos/f0t0n/aiohttp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/f0t0n/aiohttp/downloads","issues_url":"https://api.github.com/repos/f0t0n/aiohttp/issues{/number}","pulls_url":"https://api.github.com/repos/f0t0n/aiohttp/pulls{/number}","milestones_url":"https://api.github.com/repos/f0t0n/aiohttp/milestones{/number}","notifications_url":"https://api.github.com/repos/f0t0n/aiohttp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/f0t0n/aiohttp/labels{/name}","releases_url":"https://api.github.com/repos/f0t0n/aiohttp/releases{/id}","deployments_url":"https://api.github.com/repos/f0t0n/aiohttp/deployments","created_at":"2016-08-20T13:27:58Z","updated_at":"2016-08-20T13:28:00Z","pushed_at":"2016-08-23T21:09:14Z","git_url":"git://github.com/f0t0n/aiohttp.git","ssh_url":"git@github.com:f0t0n/aiohttp.git","clone_url":"https://github.com/f0t0n/aiohttp.git","svn_url":"https://github.com/f0t0n/aiohttp","homepage":"http://aiohttp.readthedocs.io","size":6968,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"KeepSafe:master","ref":"master","sha":"ee1532cc226987904666eeb0bda61445455d04e3","user":{"login":"KeepSafe","id":1377248,"avatar_url":"https://avatars.githubusercontent.com/u/1377248?v=3","gravatar_id":"","url":"https://api.github.com/users/KeepSafe","html_url":"https://github.com/KeepSafe","followers_url":"https://api.github.com/users/KeepSafe/followers","following_url":"https://api.github.com/users/KeepSafe/following{/other_user}","gists_url":"https://api.github.com/users/KeepSafe/gists{/gist_id}","starred_url":"https://api.github.com/users/KeepSafe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KeepSafe/subscriptions","organizations_url":"https://api.github.com/users/KeepSafe/orgs","repos_url":"https://api.github.com/users/KeepSafe/repos","events_url":"https://api.github.com/users/KeepSafe/events{/privacy}","received_events_url":"https://api.github.com/users/KeepSafe/received_events","type":"Organization","site_admin":false},"repo":{"id":13258039,"name":"aiohttp","full_name":"KeepSafe/aiohttp","owner":{"login":"KeepSafe","id":1377248,"avatar_url":"https://avatars.githubusercontent.com/u/1377248?v=3","gravatar_id":"","url":"https://api.github.com/users/KeepSafe","html_url":"https://github.com/KeepSafe","followers_url":"https://api.github.com/users/KeepSafe/followers","following_url":"https://api.github.com/users/KeepSafe/following{/other_user}","gists_url":"https://api.github.com/users/KeepSafe/gists{/gist_id}","starred_url":"https://api.github.com/users/KeepSafe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KeepSafe/subscriptions","organizations_url":"https://api.github.com/users/KeepSafe/orgs","repos_url":"https://api.github.com/users/KeepSafe/repos","events_url":"https://api.github.com/users/KeepSafe/events{/privacy}","received_events_url":"https://api.github.com/users/KeepSafe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/KeepSafe/aiohttp","description":"http client/server for asyncio (PEP-3156)","fork":false,"url":"https://api.github.com/repos/KeepSafe/aiohttp","forks_url":"https://api.github.com/repos/KeepSafe/aiohttp/forks","keys_url":"https://api.github.com/repos/KeepSafe/aiohttp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/KeepSafe/aiohttp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/KeepSafe/aiohttp/teams","hooks_url":"https://api.github.com/repos/KeepSafe/aiohttp/hooks","issue_events_url":"https://api.github.com/repos/KeepSafe/aiohttp/issues/events{/number}","events_url":"https://api.github.com/repos/KeepSafe/aiohttp/events","assignees_url":"https://api.github.com/repos/KeepSafe/aiohttp/assignees{/user}","branches_url":"https://api.github.com/repos/KeepSafe/aiohttp/branches{/branch}","tags_url":"https://api.github.com/repos/KeepSafe/aiohttp/tags","blobs_url":"https://api.github.com/repos/KeepSafe/aiohttp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/KeepSafe/aiohttp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/KeepSafe/aiohttp/git/refs{/sha}","trees_url":"https://api.github.com/repos/KeepSafe/aiohttp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/KeepSafe/aiohttp/statuses/{sha}","languages_url":"https://api.github.com/repos/KeepSafe/aiohttp/languages","stargazers_url":"https://api.github.com/repos/KeepSafe/aiohttp/stargazers","contributors_url":"https://api.github.com/repos/KeepSafe/aiohttp/contributors","subscribers_url":"https://api.github.com/repos/KeepSafe/aiohttp/subscribers","subscription_url":"https://api.github.com/repos/KeepSafe/aiohttp/subscription","commits_url":"https://api.github.com/repos/KeepSafe/aiohttp/commits{/sha}","git_commits_url":"https://api.github.com/repos/KeepSafe/aiohttp/git/commits{/sha}","comments_url":"https://api.github.com/repos/KeepSafe/aiohttp/comments{/number}","issue_comment_url":"https://api.github.com/repos/KeepSafe/aiohttp/issues/comments{/number}","contents_url":"https://api.github.com/repos/KeepSafe/aiohttp/contents/{+path}","compare_url":"https://api.github.com/repos/KeepSafe/aiohttp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/KeepSafe/aiohttp/merges","archive_url":"https://api.github.com/repos/KeepSafe/aiohttp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/KeepSafe/aiohttp/downloads","issues_url":"https://api.github.com/repos/KeepSafe/aiohttp/issues{/number}","pulls_url":"https://api.github.com/repos/KeepSafe/aiohttp/pulls{/number}","milestones_url":"https://api.github.com/repos/KeepSafe/aiohttp/milestones{/number}","notifications_url":"https://api.github.com/repos/KeepSafe/aiohttp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/KeepSafe/aiohttp/labels{/name}","releases_url":"https://api.github.com/repos/KeepSafe/aiohttp/releases{/id}","deployments_url":"https://api.github.com/repos/KeepSafe/aiohttp/deployments","created_at":"2013-10-01T23:04:01Z","updated_at":"2016-08-23T09:33:41Z","pushed_at":"2016-08-23T21:09:15Z","git_url":"git://github.com/KeepSafe/aiohttp.git","ssh_url":"git@github.com:KeepSafe/aiohttp.git","clone_url":"https://github.com/KeepSafe/aiohttp.git","svn_url":"https://github.com/KeepSafe/aiohttp","homepage":"http://aiohttp.readthedocs.io","size":7508,"stargazers_count":2105,"watchers_count":2105,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":371,"mirror_url":null,"open_issues_count":106,"forks":371,"open_issues":106,"watchers":2105,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/1107"},"html":{"href":"https://github.com/KeepSafe/aiohttp/pull/1107"},"issue":{"href":"https://api.github.com/repos/KeepSafe/aiohttp/issues/1107"},"comments":{"href":"https://api.github.com/repos/KeepSafe/aiohttp/issues/1107/comments"},"review_comments":{"href":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/1107/comments"},"review_comment":{"href":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/KeepSafe/aiohttp/pulls/1107/commits"},"statuses":{"href":"https://api.github.com/repos/KeepSafe/aiohttp/statuses/50f6d93abeffd8bf3ab596026287a21a54b1dbf1"}}}}
{"actor":{"display_login":"asvetlov"}}