René's URL Explorer Experiment


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

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2d8cefa8-b50a-7abc-3f2c-eb215bde6c04
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC440:3AF9A7:F56E29:15553D8:6A4E9414
html-safe-nonce796d9a3efcb63af20227796206c3db63da350f414db440a2168adc4602b2dca0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDQwOjNBRjlBNzpGNTZFMjk6MTU1NTNEODo2QTRFOTQxNCIsInZpc2l0b3JfaWQiOiI0ODIzOTc4MDM3Mzc5NzY1MjY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacab29854eaacd6d3c4669e2a3e867695aca3ad8084646dc6af3a7ef6e07bb37d6
hovercard-subject-tagissue:1963471803
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/111358/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0cb5bc0e75104676a5466566cb6c32bf86f278edf790af37b5163b0e1e541c58/python/cpython/issues/111358
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0cb5bc0e75104676a5466566cb6c32bf86f278edf790af37b5163b0e1e541c58/python/cpython/issues/111358
og:image:altBug 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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamexbeastx
hostnamegithub.com
expected-hostnamegithub.com
None41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee6a744804e8e70f97b4d5a18a94dcc63db22f97a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/111358#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F111358
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F111358
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/111358
Reloadhttps://github.com/python/cpython/issues/111358
Reloadhttps://github.com/python/cpython/issues/111358
Please reload this pagehttps://github.com/python/cpython/issues/111358
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/111358
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.6k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
shutdown_default_executor / wait_for_tstate_lock deadlock (?) after Ctrl+Chttps://github.com/python/cpython/issues/111358#top
topic-asynciohttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-asyncio%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/xbeastx
xbeastxhttps://github.com/xbeastx
on Oct 26, 2023https://github.com/python/cpython/issues/111358#issue-1963471803
https://www.roguelynn.com/words/asyncio-sync-and-threaded/https://www.roguelynn.com/words/asyncio-sync-and-threaded/
gh-111358: Fix timeout behaviour in BaseEventLoop.shutdown_default_executor #115622https://github.com/python/cpython/pull/115622
[3.12] gh-111358: Fix timeout behaviour in BaseEventLoop.shutdown_default_executor (GH-115622) #115641https://github.com/python/cpython/pull/115641
topic-asynciohttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-asyncio%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
asynciohttps://github.com/orgs/python/projects/29
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.