{"action":"created","issue":{"url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3191","repository_url":"https://api.github.com/repos/aio-libs/aiohttp","labels_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3191/labels{/name}","comments_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3191/comments","events_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3191/events","html_url":"https://github.com/aio-libs/aiohttp/issues/3191","id":349817494,"node_id":"MDU6SXNzdWUzNDk4MTc0OTQ=","number":3191,"title":"[Cleanup Context] on_startup and cleanup_ctx execution order.","user":{"login":"Maillol","id":2394534,"node_id":"MDQ6VXNlcjIzOTQ1MzQ=","avatar_url":"https://avatars1.githubusercontent.com/u/2394534?v=4","gravatar_id":"","url":"https://api.github.com/users/Maillol","html_url":"https://github.com/Maillol","followers_url":"https://api.github.com/users/Maillol/followers","following_url":"https://api.github.com/users/Maillol/following{/other_user}","gists_url":"https://api.github.com/users/Maillol/gists{/gist_id}","starred_url":"https://api.github.com/users/Maillol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Maillol/subscriptions","organizations_url":"https://api.github.com/users/Maillol/orgs","repos_url":"https://api.github.com/users/Maillol/repos","events_url":"https://api.github.com/users/Maillol/events{/privacy}","received_events_url":"https://api.github.com/users/Maillol/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-12T14:37:44Z","updated_at":"2018-08-12T14:51:34Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"## Long story short\r\n\r\nThe initialization code of Cleanup Context is alway executed before any startup signal handler.\r\n\r\nIn this code:\r\n```\r\nfrom aiohttp import web\r\n\r\nasync def startup_1(app):\r\n    print('init 1')\r\n\r\nasync def cleanup_ctx_2(app):\r\n    print('init 2')\r\n    yield\r\n    print('cleanup 2')\r\n\r\nasync def startup_3(app):\r\n    print('init 3')\r\n\r\napp = web.Application()\r\napp.on_startup.append(startup_1) \r\napp.cleanup_ctx.append(cleanup_ctx_2)\r\napp.on_startup.append(startup_3)\r\n\r\nweb.run_app(app)\r\n``` \r\n\r\nI would execute `startup_1` before `cleanup_ctx_2` initialization code.\r\n\r\nNote: Perhaps `on_startup.append` can become a shortcut for:\r\n\r\n```\r\nasync def cleanup_ctx(app):\r\n    await start_up_handler(app)\r\n    yield\r\n    # Do nothing\r\n\r\napp.cleanup_ctx.append(cleanup_ctx)\r\n``` \r\n\r\n## Expected behaviour\r\n\r\non_startup signal handlers added before cleanup context is executed before initialization code of Cleanup Context.\r\n\r\nThe example code above displays:\r\n ```\r\ninit 1\r\ninit 2\r\ninit 3\r\n======== Running on http://0.0.0.0:8080 ========\r\n(Press CTRL+C to quit)\r\n^Ccleanup context\r\n```\r\n\r\n## Actual behaviour\r\n\r\nThe example code above displays:\r\n\r\n```\r\ninit 2\r\ninit 1\r\ninit 3\r\n======== Running on http://0.0.0.0:8080 ========\r\n(Press CTRL+C to quit)\r\n^Ccleanup context\r\n```\r\n\r\n## Steps to reproduce\r\n\r\nAdd startup hander to the `app` before  `Cleanup Context`.\r\nlaunch the `app`\r\n\r\n## Your environment\r\n\r\naiohtpp=3.3.2"},"comment":{"url":"https://api.github.com/repos/aio-libs/aiohttp/issues/comments/412347985","html_url":"https://github.com/aio-libs/aiohttp/issues/3191#issuecomment-412347985","issue_url":"https://api.github.com/repos/aio-libs/aiohttp/issues/3191","id":412347985,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMjM0Nzk4NQ==","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},"created_at":"2018-08-12T14:51:34Z","updated_at":"2018-08-12T14:51:34Z","author_association":"MEMBER","body":"It is the design decision.\r\n`on_cleanup` order is also affected.\r\nYou can try to prepare a patch but I doubt if elegant and clean solution for mixing cleanup contexts and `on_startup`/`on_cleanup` exists."}}
{"actor":{"display_login":"asvetlov"}}