Title: shutdown_default_executor / wait_for_tstate_lock deadlock (?) after Ctrl+C · Issue #111358 · python/cpython · GitHub
Open Graph Title: shutdown_default_executor / wait_for_tstate_lock deadlock (?) after Ctrl+C · Issue #111358 · python/cpython
X Title: shutdown_default_executor / wait_for_tstate_lock deadlock (?) after Ctrl+C · Issue #111358 · python/cpython
Description: Bug report Bug description: Blocking function running in thread executor will produce deadlock on shutdown after Ctrl+C pressed. Here is minimal reproducing example: import asyncio import time def blocking(): print("sleep start") time.sl...
Open Graph Description: Bug report Bug description: Blocking function running in thread executor will produce deadlock on shutdown after Ctrl+C pressed. Here is minimal reproducing example: import asyncio import time def ...
X Description: Bug report Bug description: Blocking function running in thread executor will produce deadlock on shutdown after Ctrl+C pressed. Here is minimal reproducing example: import asyncio import time def ...
Opengraph URL: https://github.com/python/cpython/issues/111358
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"shutdown_default_executor / wait_for_tstate_lock deadlock (?) after Ctrl+C","articleBody":"# Bug report\n\n### Bug description:\n\nBlocking function running in thread executor will produce deadlock on shutdown after Ctrl+C pressed.\n\nHere is minimal reproducing **example**:\n```python\nimport asyncio\nimport time\n\ndef blocking():\n print(\"sleep start\")\n time.sleep(1000)\n print(\"sleep end\")\n\nasync def main():\n await asyncio.to_thread(blocking)\n\nasyncio.run(main())\n```\n\n**Steps to reproduce**:\n1. Run script\n2. Try press Ctrl+C when blocking func sleeps | Nothing produced\n3. If press Ctrl+C again | Will print KeyboardInterrupt exception but script will still hang\n4. If press Ctrl+C again | Will print one more KeyboardInterrupt and will shutdown.\n\n(Tested on 3.9\u003c=python\u003c=3.12 on Ubuntu 22.04 all have same behaviour)\n\n\n**Output**:\n```shell\n$ python3.11 test.py \nsleep start\n^C^CTraceback (most recent call last):\n File \"/usr/lib/python3.11/asyncio/runners.py\", line 118, in run\n return self._loop.run_until_complete(task)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/lib/python3.11/asyncio/base_events.py\", line 653, in run_until_complete\n return future.result()\n ^^^^^^^^^^^^^^^\n File \"/home/ilya/test.py\", line 13, in main\n await asyncio.to_thread(blocking)\n File \"/usr/lib/python3.11/asyncio/threads.py\", line 25, in to_thread\n return await loop.run_in_executor(None, func_call)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nasyncio.exceptions.CancelledError\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/usr/lib/python3.11/asyncio/runners.py\", line 190, in run\n return runner.run(main)\n ^^^^^^^^^^^^^^^^\n File \"/usr/lib/python3.11/asyncio/runners.py\", line 123, in run\n raise KeyboardInterrupt()\nKeyboardInterrupt\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/home/ilya/test.py\", line 15, in \u003cmodule\u003e\n asyncio.run(main())\n File \"/usr/lib/python3.11/asyncio/runners.py\", line 189, in run\n with Runner(debug=debug) as runner:\n File \"/usr/lib/python3.11/asyncio/runners.py\", line 63, in __exit__\n self.close()\n File \"/usr/lib/python3.11/asyncio/runners.py\", line 73, in close\n loop.run_until_complete(loop.shutdown_default_executor())\n File \"/usr/lib/python3.11/asyncio/base_events.py\", line 640, in run_until_complete\n self.run_forever()\n File \"/usr/lib/python3.11/asyncio/base_events.py\", line 607, in run_forever\n self._run_once()\n File \"/usr/lib/python3.11/asyncio/base_events.py\", line 1884, in _run_once\n event_list = self._selector.select(timeout)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/lib/python3.11/selectors.py\", line 468, in select\n fd_event_list = self._selector.poll(timeout, max_ev)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nKeyboardInterrupt\n^CException ignored in: \u003cmodule 'threading' from '/usr/lib/python3.11/threading.py'\u003e\nTraceback (most recent call last):\n File \"/usr/lib/python3.11/threading.py\", line 1560, in _shutdown\n atexit_call()\n File \"/usr/lib/python3.11/concurrent/futures/thread.py\", line 31, in _python_exit\n t.join()\n File \"/usr/lib/python3.11/threading.py\", line 1119, in join\n self._wait_for_tstate_lock()\n File \"/usr/lib/python3.11/threading.py\", line 1139, in _wait_for_tstate_lock\n if lock.acquire(block, timeout):\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nKeyboardInterrupt: \n```\n\n**Additional**:\nFound a blog post https://www.roguelynn.com/words/asyncio-sync-and-threaded/ with looks like similar behavior back in 2019 where someone is trying to workaround this.\n\n### CPython versions tested on:\n\n3.9, 3.10, 3.11, 3.12\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-115622\n* gh-115641\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/xbeastx","@type":"Person","name":"xbeastx"},"datePublished":"2023-10-26T12:37:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/111358/cpython/issues/111358"}
| 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:2d8cefa8-b50a-7abc-3f2c-eb215bde6c04 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C440:3AF9A7:F56E29:15553D8:6A4E9414 |
| html-safe-nonce | 796d9a3efcb63af20227796206c3db63da350f414db440a2168adc4602b2dca0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDQwOjNBRjlBNzpGNTZFMjk6MTU1NTNEODo2QTRFOTQxNCIsInZpc2l0b3JfaWQiOiI0ODIzOTc4MDM3Mzc5NzY1MjY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ab29854eaacd6d3c4669e2a3e867695aca3ad8084646dc6af3a7ef6e07bb37d6 |
| hovercard-subject-tag | issue:1963471803 |
| 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/111358/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0cb5bc0e75104676a5466566cb6c32bf86f278edf790af37b5163b0e1e541c58/python/cpython/issues/111358 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0cb5bc0e75104676a5466566cb6c32bf86f278edf790af37b5163b0e1e541c58/python/cpython/issues/111358 |
| og:image:alt | Bug report Bug description: Blocking function running in thread executor will produce deadlock on shutdown after Ctrl+C pressed. Here is minimal reproducing example: import asyncio import time def ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | xbeastx |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c |
| 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 | e6a744804e8e70f97b4d5a18a94dcc63db22f97a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width