Title: Cannot cleanly shut down an asyncio based server · Issue #113538 · python/cpython · GitHub
Open Graph Title: Cannot cleanly shut down an asyncio based server · Issue #113538 · python/cpython
X Title: Cannot cleanly shut down an asyncio based server · Issue #113538 · python/cpython
Description: Bug report Bug description: When writing an asyncio based service, you basically have this sequence: Create an event loop Register a SIGTERM handler Start your server loop.run_forever() SIGTERM causes a loop.stop() Close the server Close...
Open Graph Description: Bug report Bug description: When writing an asyncio based service, you basically have this sequence: Create an event loop Register a SIGTERM handler Start your server loop.run_forever() SIGTERM cau...
X Description: Bug report Bug description: When writing an asyncio based service, you basically have this sequence: Create an event loop Register a SIGTERM handler Start your server loop.run_forever() SIGTERM cau...
Opengraph URL: https://github.com/python/cpython/issues/113538
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot cleanly shut down an asyncio based server","articleBody":"# Bug report\n\n### Bug description:\n\nWhen writing an asyncio based service, you basically have this sequence:\n\n1. Create an event loop\n2. Register a SIGTERM handler\n3. Start your server\n4. `loop.run_forever()`\n5. SIGTERM causes a `loop.stop()`\n6. Close the server\n7. Close event loop\n\nIf there are any connections active at this point, then they don't get discarded until interpreter shutdown, with the result that you get a bunch of ResourceWarnings (and cleanup code might not run).\n\nIt would be very useful if there was a `Server.close_clients()` or something like that. Even a `Server.all_transports()` would be useful, as then you could do something similar as when doing a `Task.cancel()` on what you get from `loop.all_tasks()`.\n\nWe could poke at `Server._transports`, but that is something internal that might change in the future.\n\nThere is `Server.wait_closed()`, but that hangs until all clients have gracefully disconnected. It doesn't help us when we want to shut down the service *now*.\n\n### CPython versions tested on:\n\n3.12\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-113690\n* gh-113713\n* gh-113714\n* gh-114432\n* gh-116632\n* gh-116784\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/CendioOssman","@type":"Person","name":"CendioOssman"},"datePublished":"2023-12-28T10:14:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":33},"url":"https://github.com/113538/cpython/issues/113538"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6c43cb84-9893-0099-6bab-386b07a2e1d5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A5E6:247E0C:1472234:1C3DA72:696AA1BF |
| html-safe-nonce | 2c35c280a81f158ae3e408a6b17a9a01694e02ba7d8290cc6e6a819f857e1e10 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNUU2OjI0N0UwQzoxNDcyMjM0OjFDM0RBNzI6Njk2QUExQkYiLCJ2aXNpdG9yX2lkIjoiMzU4MDY1ODEyNjk5MTA0MDk1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dbc1553b90f94938dda54acfa89b827db8e20c18ae56ddb6547e0e3bb9b6a3d0 |
| hovercard-subject-tag | issue:2058252897 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/113538/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8722b9684f66c3348352781afc2f1db7c6c931f70ef4a348270c33f1c79eafe3/python/cpython/issues/113538 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8722b9684f66c3348352781afc2f1db7c6c931f70ef4a348270c33f1c79eafe3/python/cpython/issues/113538 |
| og:image:alt | Bug report Bug description: When writing an asyncio based service, you basically have this sequence: Create an event loop Register a SIGTERM handler Start your server loop.run_forever() SIGTERM cau... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CendioOssman |
| hostname | github.com |
| expected-hostname | github.com |
| None | a51f97dbb9326f71c08ecb61577457d543c602124d1a2672871258ef37ac5261 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4bd0eac606c70914085176ef312ebdcd97a8cdf1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width