{"action":"created","comment":{"url":"https://api.github.com/repos/aio-libs/aiohttp/pulls/comments/240789246","pull_request_review_id":183901244,"id":240789246,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MDc4OTI0Ng==","diff_hunk":"@@ -393,6 +393,82 @@ and safe to use as the key.\n Otherwise, something based on your company name/url would be satisfactory (i.e.\n ``org.company.app``).\n \n+\n+.. _aiohttp-web-contextvars:\n+\n+\n+ContextVars support\n+-------------------\n+\n+Starting from Python 3.7 asyncio has :mod:`Context Variables <contextvars>` as a\n+context-local storage (a generalization of thread-local concept that works with asyncio\n+tasks also).\n+\n+\n+*aiohttp* server supports it in the following way:\n+\n+* A server inherits a current task's context used by the server\n+  creation. :func:`aiohttp.web.run_app()` runs a task for handling all underlying dirty\n+  job, but :ref:`aiohttp-web-app-runners` can be used as well.\n+\n+* Application initialization / finalization events (:attr:`Application.cleanup_ctx`,\n+  :attr:`Application.on_startup` and :attr:`Application.on_shutdown`,\n+  :attr:`Application.on_cleanup`) are executed inside the same context.\n+\n+  E.g. all context modifications made on application startup a visible on teardown.\n+\n+* On every request handling *aiohttp* creates a context copy. :term:`web-handler` has\n+  all variables installed on initialization stage. But the context modification made by\n+  a handler or middleware is invisible to another HTTP request handling call.\n+\n+An example of context vars usage::\n+\n+    from contextvars import ContextVar","path":"docs/web_advanced.rst","position":34,"original_position":34,"commit_id":"a48568b13d44432ae5e73727a82a3b73451b386a","original_commit_id":"a48568b13d44432ae5e73727a82a3b73451b386a","user":{"login":"webknjaz","id":578543,"node_id":"MDQ6VXNlcjU3ODU0Mw==","avatar_url":"https://avatars2.githubusercontent.com/u/578543?v=4","gravatar_id":"","url":"https://api.github.com/users/webknjaz","html_url":"https://github.com/webknjaz","followers_url":"https://api.github.com/users/webknjaz/followers","following_url":"https://api.github.com/users/webknjaz/following{/other_user}","gists_url":"https://api.github.com/users/webknjaz/gists{/gist_id}","starred_url":"https://api.github.com/users/webknjaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webknjaz/subscriptions","organizations_url":"https://api.github.com/users/webknjaz/orgs","repos_url":"https://api.github.com/users/webknjaz/repos","events_url":"https://api.github.com/users/webknjaz/events{/privacy}","received_events_url":"https://api.github.com/users/webknjaz/received_events","type":"User","site_admin":false},"body":"Please mark it as a python block","created_at":"2018-12-11T21:01:38Z","updated_at":"2018-12-11T21:01:38Z","html_url":"https://github.com/aio-libs/aiohttp/pull/3446#discussion_r240789246","pull_request_url":"https://api.github.com/repos/aio-libs/aiohttp/pulls/3446","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/aio-libs/aiohttp/pulls/comments/240789246"},"html":{"href":"https://github.com/aio-libs/aiohttp/pull/3446#discussion_r240789246"},"pull_request":{"href":"https://api.github.com/repos/aio-libs/aiohttp/pulls/3446"}}},"pull_request":{"url":"https://api.github.com/repos/aio-libs/aiohttp/pulls/3446","id":237806729,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM3ODA2NzI5","html_url":"https://github.com/aio-libs/aiohttp/pull/3446","diff_url":"https://github.com/aio-libs/aiohttp/pull/3446.diff","patch_url":"https://github.com/aio-libs/aiohttp/pull/3446.patch","issue_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3446","number":3446,"state":"open","locked":false,"title":"Contextvars support","user":{"login":"asvetlov","id":356399,"node_id":"MDQ6VXNlcjM1NjM5OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/356399?v=4","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":"@samuelcolvin maybe you have a suggestion for documentation polishing?","created_at":"2018-12-11T19:52:18Z","updated_at":"2018-12-11T21:01:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"affe8a601559b265d65b8c8a6865b3ac4fa09183","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/aio-libs/aiohttp/pulls/3446/commits","review_comments_url":"https://api.github.com/repos/aio-libs/aiohttp/pulls/3446/comments","review_comment_url":"https://api.github.com/repos/aio-libs/aiohttp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3446/comments","statuses_url":"https://api.github.com/repos/aio-libs/aiohttp/statuses/a48568b13d44432ae5e73727a82a3b73451b386a","head":{"label":"aio-libs:contextvars-support","ref":"contextvars-support","sha":"a48568b13d44432ae5e73727a82a3b73451b386a","user":{"login":"aio-libs","id":7049303,"node_id":"MDEyOk9yZ2FuaXphdGlvbjcwNDkzMDM=","avatar_url":"https://avatars2.githubusercontent.com/u/7049303?v=4","gravatar_id":"","url":"https://api.github.com/users/aio-libs","html_url":"https://github.com/aio-libs","followers_url":"https://api.github.com/users/aio-libs/followers","following_url":"https://api.github.com/users/aio-libs/following{/other_user}","gists_url":"https://api.github.com/users/aio-libs/gists{/gist_id}","starred_url":"https://api.github.com/users/aio-libs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aio-libs/subscriptions","organizations_url":"https://api.github.com/users/aio-libs/orgs","repos_url":"https://api.github.com/users/aio-libs/repos","events_url":"https://api.github.com/users/aio-libs/events{/privacy}","received_events_url":"https://api.github.com/users/aio-libs/received_events","type":"Organization","site_admin":false},"repo":{"id":13258039,"node_id":"MDEwOlJlcG9zaXRvcnkxMzI1ODAzOQ==","name":"aiohttp","full_name":"aio-libs/aiohttp","private":false,"owner":{"login":"aio-libs","id":7049303,"node_id":"MDEyOk9yZ2FuaXphdGlvbjcwNDkzMDM=","avatar_url":"https://avatars2.githubusercontent.com/u/7049303?v=4","gravatar_id":"","url":"https://api.github.com/users/aio-libs","html_url":"https://github.com/aio-libs","followers_url":"https://api.github.com/users/aio-libs/followers","following_url":"https://api.github.com/users/aio-libs/following{/other_user}","gists_url":"https://api.github.com/users/aio-libs/gists{/gist_id}","starred_url":"https://api.github.com/users/aio-libs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aio-libs/subscriptions","organizations_url":"https://api.github.com/users/aio-libs/orgs","repos_url":"https://api.github.com/users/aio-libs/repos","events_url":"https://api.github.com/users/aio-libs/events{/privacy}","received_events_url":"https://api.github.com/users/aio-libs/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/aio-libs/aiohttp","description":"Asynchronous HTTP client/server framework for asyncio and Python","fork":false,"url":"https://api.github.com/repos/aio-libs/aiohttp","forks_url":"https://api.github.com/repos/aio-libs/aiohttp/forks","keys_url":"https://api.github.com/repos/aio-libs/aiohttp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aio-libs/aiohttp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aio-libs/aiohttp/teams","hooks_url":"https://api.github.com/repos/aio-libs/aiohttp/hooks","issue_events_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/events{/number}","events_url":"https://api.github.com/repos/aio-libs/aiohttp/events","assignees_url":"https://api.github.com/repos/aio-libs/aiohttp/assignees{/user}","branches_url":"https://api.github.com/repos/aio-libs/aiohttp/branches{/branch}","tags_url":"https://api.github.com/repos/aio-libs/aiohttp/tags","blobs_url":"https://api.github.com/repos/aio-libs/aiohttp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aio-libs/aiohttp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aio-libs/aiohttp/git/refs{/sha}","trees_url":"https://api.github.com/repos/aio-libs/aiohttp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aio-libs/aiohttp/statuses/{sha}","languages_url":"https://api.github.com/repos/aio-libs/aiohttp/languages","stargazers_url":"https://api.github.com/repos/aio-libs/aiohttp/stargazers","contributors_url":"https://api.github.com/repos/aio-libs/aiohttp/contributors","subscribers_url":"https://api.github.com/repos/aio-libs/aiohttp/subscribers","subscription_url":"https://api.github.com/repos/aio-libs/aiohttp/subscription","commits_url":"https://api.github.com/repos/aio-libs/aiohttp/commits{/sha}","git_commits_url":"https://api.github.com/repos/aio-libs/aiohttp/git/commits{/sha}","comments_url":"https://api.github.com/repos/aio-libs/aiohttp/comments{/number}","issue_comment_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/comments{/number}","contents_url":"https://api.github.com/repos/aio-libs/aiohttp/contents/{+path}","compare_url":"https://api.github.com/repos/aio-libs/aiohttp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aio-libs/aiohttp/merges","archive_url":"https://api.github.com/repos/aio-libs/aiohttp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aio-libs/aiohttp/downloads","issues_url":"https://api.github.com/repos/aio-libs/aiohttp/issues{/number}","pulls_url":"https://api.github.com/repos/aio-libs/aiohttp/pulls{/number}","milestones_url":"https://api.github.com/repos/aio-libs/aiohttp/milestones{/number}","notifications_url":"https://api.github.com/repos/aio-libs/aiohttp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aio-libs/aiohttp/labels{/name}","releases_url":"https://api.github.com/repos/aio-libs/aiohttp/releases{/id}","deployments_url":"https://api.github.com/repos/aio-libs/aiohttp/deployments","created_at":"2013-10-01T23:04:01Z","updated_at":"2018-12-11T15:03:50Z","pushed_at":"2018-12-11T20:17:25Z","git_url":"git://github.com/aio-libs/aiohttp.git","ssh_url":"git@github.com:aio-libs/aiohttp.git","clone_url":"https://github.com/aio-libs/aiohttp.git","svn_url":"https://github.com/aio-libs/aiohttp","homepage":"https://docs.aiohttp.org","size":14093,"stargazers_count":6550,"watchers_count":6550,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1008,"mirror_url":null,"archived":false,"open_issues_count":172,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":1008,"open_issues":172,"watchers":6550,"default_branch":"master"}},"base":{"label":"aio-libs:master","ref":"master","sha":"b0da90c9a2c71f858254f3503a56f339d5603531","user":{"login":"aio-libs","id":7049303,"node_id":"MDEyOk9yZ2FuaXphdGlvbjcwNDkzMDM=","avatar_url":"https://avatars2.githubusercontent.com/u/7049303?v=4","gravatar_id":"","url":"https://api.github.com/users/aio-libs","html_url":"https://github.com/aio-libs","followers_url":"https://api.github.com/users/aio-libs/followers","following_url":"https://api.github.com/users/aio-libs/following{/other_user}","gists_url":"https://api.github.com/users/aio-libs/gists{/gist_id}","starred_url":"https://api.github.com/users/aio-libs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aio-libs/subscriptions","organizations_url":"https://api.github.com/users/aio-libs/orgs","repos_url":"https://api.github.com/users/aio-libs/repos","events_url":"https://api.github.com/users/aio-libs/events{/privacy}","received_events_url":"https://api.github.com/users/aio-libs/received_events","type":"Organization","site_admin":false},"repo":{"id":13258039,"node_id":"MDEwOlJlcG9zaXRvcnkxMzI1ODAzOQ==","name":"aiohttp","full_name":"aio-libs/aiohttp","private":false,"owner":{"login":"aio-libs","id":7049303,"node_id":"MDEyOk9yZ2FuaXphdGlvbjcwNDkzMDM=","avatar_url":"https://avatars2.githubusercontent.com/u/7049303?v=4","gravatar_id":"","url":"https://api.github.com/users/aio-libs","html_url":"https://github.com/aio-libs","followers_url":"https://api.github.com/users/aio-libs/followers","following_url":"https://api.github.com/users/aio-libs/following{/other_user}","gists_url":"https://api.github.com/users/aio-libs/gists{/gist_id}","starred_url":"https://api.github.com/users/aio-libs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aio-libs/subscriptions","organizations_url":"https://api.github.com/users/aio-libs/orgs","repos_url":"https://api.github.com/users/aio-libs/repos","events_url":"https://api.github.com/users/aio-libs/events{/privacy}","received_events_url":"https://api.github.com/users/aio-libs/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/aio-libs/aiohttp","description":"Asynchronous HTTP client/server framework for asyncio and Python","fork":false,"url":"https://api.github.com/repos/aio-libs/aiohttp","forks_url":"https://api.github.com/repos/aio-libs/aiohttp/forks","keys_url":"https://api.github.com/repos/aio-libs/aiohttp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aio-libs/aiohttp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aio-libs/aiohttp/teams","hooks_url":"https://api.github.com/repos/aio-libs/aiohttp/hooks","issue_events_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/events{/number}","events_url":"https://api.github.com/repos/aio-libs/aiohttp/events","assignees_url":"https://api.github.com/repos/aio-libs/aiohttp/assignees{/user}","branches_url":"https://api.github.com/repos/aio-libs/aiohttp/branches{/branch}","tags_url":"https://api.github.com/repos/aio-libs/aiohttp/tags","blobs_url":"https://api.github.com/repos/aio-libs/aiohttp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aio-libs/aiohttp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aio-libs/aiohttp/git/refs{/sha}","trees_url":"https://api.github.com/repos/aio-libs/aiohttp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aio-libs/aiohttp/statuses/{sha}","languages_url":"https://api.github.com/repos/aio-libs/aiohttp/languages","stargazers_url":"https://api.github.com/repos/aio-libs/aiohttp/stargazers","contributors_url":"https://api.github.com/repos/aio-libs/aiohttp/contributors","subscribers_url":"https://api.github.com/repos/aio-libs/aiohttp/subscribers","subscription_url":"https://api.github.com/repos/aio-libs/aiohttp/subscription","commits_url":"https://api.github.com/repos/aio-libs/aiohttp/commits{/sha}","git_commits_url":"https://api.github.com/repos/aio-libs/aiohttp/git/commits{/sha}","comments_url":"https://api.github.com/repos/aio-libs/aiohttp/comments{/number}","issue_comment_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/comments{/number}","contents_url":"https://api.github.com/repos/aio-libs/aiohttp/contents/{+path}","compare_url":"https://api.github.com/repos/aio-libs/aiohttp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aio-libs/aiohttp/merges","archive_url":"https://api.github.com/repos/aio-libs/aiohttp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aio-libs/aiohttp/downloads","issues_url":"https://api.github.com/repos/aio-libs/aiohttp/issues{/number}","pulls_url":"https://api.github.com/repos/aio-libs/aiohttp/pulls{/number}","milestones_url":"https://api.github.com/repos/aio-libs/aiohttp/milestones{/number}","notifications_url":"https://api.github.com/repos/aio-libs/aiohttp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aio-libs/aiohttp/labels{/name}","releases_url":"https://api.github.com/repos/aio-libs/aiohttp/releases{/id}","deployments_url":"https://api.github.com/repos/aio-libs/aiohttp/deployments","created_at":"2013-10-01T23:04:01Z","updated_at":"2018-12-11T15:03:50Z","pushed_at":"2018-12-11T20:17:25Z","git_url":"git://github.com/aio-libs/aiohttp.git","ssh_url":"git@github.com:aio-libs/aiohttp.git","clone_url":"https://github.com/aio-libs/aiohttp.git","svn_url":"https://github.com/aio-libs/aiohttp","homepage":"https://docs.aiohttp.org","size":14093,"stargazers_count":6550,"watchers_count":6550,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1008,"mirror_url":null,"archived":false,"open_issues_count":172,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":1008,"open_issues":172,"watchers":6550,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/aio-libs/aiohttp/pulls/3446"},"html":{"href":"https://github.com/aio-libs/aiohttp/pull/3446"},"issue":{"href":"https://api.github.com/repos/aio-libs/aiohttp/issues/3446"},"comments":{"href":"https://api.github.com/repos/aio-libs/aiohttp/issues/3446/comments"},"review_comments":{"href":"https://api.github.com/repos/aio-libs/aiohttp/pulls/3446/comments"},"review_comment":{"href":"https://api.github.com/repos/aio-libs/aiohttp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aio-libs/aiohttp/pulls/3446/commits"},"statuses":{"href":"https://api.github.com/repos/aio-libs/aiohttp/statuses/a48568b13d44432ae5e73727a82a3b73451b386a"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"webknjaz"}}