Title: Coroutine with asyncio.sleep() hangs when run in a different thread · Issue #312 · python/asyncio · GitHub
Open Graph Title: Coroutine with asyncio.sleep() hangs when run in a different thread · Issue #312 · python/asyncio
X Title: Coroutine with asyncio.sleep() hangs when run in a different thread · Issue #312 · python/asyncio
Description: Here is my code: import asyncio from threading import Thread async def onRequest(data): print('got request: {}'.format(data)) await asyncio.sleep(1) print('finished processing request {}'.format(data)) loop = asyncio.get_event_loop() loo...
Open Graph Description: Here is my code: import asyncio from threading import Thread async def onRequest(data): print('got request: {}'.format(data)) await asyncio.sleep(1) print('finished processing request {}'.format(da...
X Description: Here is my code: import asyncio from threading import Thread async def onRequest(data): print('got request: {}'.format(data)) await asyncio.sleep(1) print('finished processing request {...
Opengraph URL: https://github.com/python/asyncio/issues/312
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Coroutine with asyncio.sleep() hangs when run in a different thread","articleBody":"Here is my code:\n\n``` python\nimport asyncio\nfrom threading import Thread\n\n\nasync def onRequest(data):\n print('got request: {}'.format(data))\n await asyncio.sleep(1)\n print('finished processing request {}'.format(data))\n\nloop = asyncio.get_event_loop()\nloop.set_debug(True)\n\ndef child_executor():\n loop.run_forever()\n\nchild = Thread(target=child_executor, name=\"child\")\n\ndef request(data):\n asyncio.run_coroutine_threadsafe(onRequest(data), loop)\n\nchild.start()\n\nrequest(4)\n```\n\nThis produces the following output:\n\n```\ngot request: 4\n```\n\nand then it just hangs, without the 'finished processing request' message. If I press ctrl^C, it outputs the following message, which doesn't look very interesting:\n\n```\nException ignored in: \u003cmodule 'threading' from '/home/ubuntu/lib/python3.5/threading.py'\u003e\nTraceback (most recent call last):\n File \"/home/ubuntu/lib/python3.5/threading.py\", line 1288, in _shutdown\n t.join()\n File \"/home/ubuntu/lib/python3.5/threading.py\", line 1054, in join\n self._wait_for_tstate_lock()\n File \"/home/ubuntu/lib/python3.5/threading.py\", line 1070, in _wait_for_tstate_lock\n elif lock.acquire(block, timeout):\nKeyboardInterrupt\n```\n","author":{"url":"https://github.com/mikeyhew","@type":"Person","name":"mikeyhew"},"datePublished":"2016-01-15T14:42:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/312/asyncio/issues/312"}
| 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:bec8e4e1-ad7b-fd27-31af-616ecb93b6ae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CA9E:39F63:1CCB2DD:2811838:6A5F3E12 |
| html-safe-nonce | a44f769e1f2c218f3a0c0a689fc5b6c7fee225af041845ef449f4328c16f221d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTlFOjM5RjYzOjFDQ0IyREQ6MjgxMTgzODo2QTVGM0UxMiIsInZpc2l0b3JfaWQiOiI4MDQ1MjM0MzU1ODM1OTc3MjM0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e32f3b12f4ef325ad0770c043bda7848a24e0bb3c3ac606a4b74fc43a49c65e6 |
| hovercard-subject-tag | issue:126885377 |
| 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/asyncio/312/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c35fe05b0186d4729890188d8f5bfcb14a9812b197689627fa716ebcaaaee88d/python/asyncio/issues/312 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c35fe05b0186d4729890188d8f5bfcb14a9812b197689627fa716ebcaaaee88d/python/asyncio/issues/312 |
| og:image:alt | Here is my code: import asyncio from threading import Thread async def onRequest(data): print('got request: {}'.format(data)) await asyncio.sleep(1) print('finished processing request {}'.format(da... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mikeyhew |
| hostname | github.com |
| expected-hostname | github.com |
| None | ab2497d9345a59709926b385d88458fa5932c82ec066288448eb68b34cbcbbda |
| turbo-cache-control | no-preview |
| go-import | github.com/python/asyncio git https://github.com/python/asyncio.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 33739295 |
| octolytics-dimension-repository_nwo | python/asyncio |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 33739295 |
| octolytics-dimension-repository_network_root_nwo | python/asyncio |
| 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 | ba0ac57287507693938b0a2de45402a22cda0785 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width