Title: asyncio signal handler receives signals from child processes · Issue #94454 · python/cpython · GitHub
Open Graph Title: asyncio signal handler receives signals from child processes · Issue #94454 · python/cpython
X Title: asyncio signal handler receives signals from child processes · Issue #94454 · python/cpython
Description: Bug report Today I ran into a very weird behaviour in one of my projects, that uses asyncio and multiprocessing. When I interrupted the program with a Ctrl-C on the terminal, the signal handler set in asyncio with loop.add_signal_handler...
Open Graph Description: Bug report Today I ran into a very weird behaviour in one of my projects, that uses asyncio and multiprocessing. When I interrupted the program with a Ctrl-C on the terminal, the signal handler set...
X Description: Bug report Today I ran into a very weird behaviour in one of my projects, that uses asyncio and multiprocessing. When I interrupted the program with a Ctrl-C on the terminal, the signal handler set...
Opengraph URL: https://github.com/python/cpython/issues/94454
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"asyncio signal handler receives signals from child processes","articleBody":"**Bug report**\r\n\r\nToday I ran into a very weird behaviour in one of my projects, that uses asyncio and multiprocessing.\r\nWhen I interrupted the program with a Ctrl-C on the terminal, the signal handler set in asyncio with `loop.add_signal_handler` was triggered multiple times! Further inspection showed, that if I manually send a `SIGINT` to one of the worker child processes, it triggered the main process signal handler.\r\n\r\nI could trace the issue to the socket used by asyncio to receive the signals via `signal.set_wakeup_fd`, which seems to receive the signal bytes also from the child processes.\r\n\r\nRunning `signal.set_wakeup_fd(-1)` at least once in the worker processes worked as a workaround for me but cannot be the final solution.\r\n\r\nAlso, it seems, that other signal operations also can clear the issue (for example some automatically manager child processes did not trigger the bug, as they seem to ignore `SIGINT`).\r\n\r\nIn my project I used `concurrent.futures.ProcessPoolExecutor`, but I don't think that matters, as long as the signal handler (and wakeup fd) is set before the child is started.\r\n\r\n**Your environment**\r\n\r\n- CPython versions tested on:\r\nPython 3.10.4\r\n- Operating system and architecture:\r\nKali Linux rolling with kernel: Debian 5.16.18-1kali1 (2022-04-01) x86_64\r\n\r\n**Bug output**\r\n[asyncio_signal_bug.py.txt](https://github.com/python/cpython/files/9021468/asyncio_signal_bug.py.txt)\r\n\r\n```\r\n# python3 asyncio_signal_bug.py\r\n394236 Signal Handler set\r\n394237 Worker 1 started\r\n394240 Worker 2 started\r\n^C394236 received signal: Signals.SIGINT\r\n394236 received signal: Signals.SIGINT\r\n394236 received signal: Signals.SIGINT\r\n^C394236 received signal: Signals.SIGINT\r\n394236 received signal: Signals.SIGINT\r\n394236 received signal: Signals.SIGINT\r\n\r\n# python3 asyncio_signal_bug.py --set-in-children\r\n394241 Signal Handler set\r\n394242 Worker 1 started\r\n394245 Worker 2 started\r\n^C394241 received signal: Signals.SIGINT\r\n^C394241 received signal: Signals.SIGINT\r\n^C394241 received signal: Signals.SIGINT\r\n^C394241 received signal: Signals.SIGINT\r\n^C394241 received signal: Signals.SIGINT\r\n^C394241 received signal: Signals.SIGINT\r\n```\r\nNotice, that in the first block, for every ^C, there are three signals received, whereas in the second block (if `signal.set_wakeup_fd(-1)` was called in the workers) there is only one.","author":{"url":"https://github.com/ozppupbg","@type":"Person","name":"ozppupbg"},"datePublished":"2022-06-30T16:00:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/94454/cpython/issues/94454"}
| 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:5471e255-fe22-bb7a-9eb6-bc410c5b6d23 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8D6:169ED8:29092F:37158F:69697959 |
| html-safe-nonce | 00d2a9baa1e4accbfbc026dd6d79a07cee6705126e2a494ffcc51bf2b8cd0519 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEQ2OjE2OUVEODoyOTA5MkY6MzcxNThGOjY5Njk3OTU5IiwidmlzaXRvcl9pZCI6IjcyMTc5ODA5MzY4NjU1NDQ1MzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 55b9022a3c000015bbf30b9fbf92fdff79f615830dfe1ff060b4158b2ebf1598 |
| hovercard-subject-tag | issue:1290349035 |
| 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/94454/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fef4db892ac79f96393e8048e48f6a03c5052684c142d954e18eee12ddc4da04/python/cpython/issues/94454 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fef4db892ac79f96393e8048e48f6a03c5052684c142d954e18eee12ddc4da04/python/cpython/issues/94454 |
| og:image:alt | Bug report Today I ran into a very weird behaviour in one of my projects, that uses asyncio and multiprocessing. When I interrupted the program with a Ctrl-C on the terminal, the signal handler set... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ozppupbg |
| hostname | github.com |
| expected-hostname | github.com |
| None | c6f193beb8ff08443adc07685d75302ab8aaf0a135f6e251c3ff3112c8deb881 |
| 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 | 212e3e3d3298bf5b313830edfd2399e869f7ea76 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width