Title: Graceful loop shutdown with running executor tasks · Issue #258 · python/asyncio · GitHub
Open Graph Title: Graceful loop shutdown with running executor tasks · Issue #258 · python/asyncio
X Title: Graceful loop shutdown with running executor tasks · Issue #258 · python/asyncio
Description: When I send a long task to tread-pool executor and immediately close the loop without waiting future returned by .run_in_executor() call I get exception report in logs: ERROR:concurrent.futures:exception calling callback for Open Graph Description: When I send a long task to tread-pool executor and immediately close the loop without waiting future returned by .run_in_executor() call I get exception report in logs: ERROR:concurrent.futures:exc...
X Description: When I send a long task to tread-pool executor and immediately close the loop without waiting future returned by .run_in_executor() call I get exception report in logs: ERROR:concurrent.futures:exc...
Opengraph URL: https://github.com/python/asyncio/issues/258
X: @github
Domain: patch-diff.githubusercontent.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Graceful loop shutdown with running executor tasks","articleBody":"When I send a long task to tread-pool executor and immediately close the loop without waiting future returned by `.run_in_executor()` call I get exception report in logs:\n\n```\nERROR:concurrent.futures:exception calling callback for \u003cFuture at 0x7ff1ae393630 state=finished returned NoneType\u003e\nTraceback (most recent call last):\n File \"/usr/lib/python3.4/concurrent/futures/_base.py\", line 297, in _invoke_callbacks\n callback(self)\n File \"/home/andrew/projects/asyncio/asyncio/futures.py\", line 410, in \u003clambda\u003e\n new_future._copy_state, future))\n File \"/home/andrew/projects/asyncio/asyncio/base_events.py\", line 487, in call_soon_threadsafe\n handle = self._call_soon(callback, args)\n File \"/home/andrew/projects/asyncio/asyncio/base_events.py\", line 461, in _call_soon\n self._check_closed()\n File \"/home/andrew/projects/asyncio/asyncio/base_events.py\", line 288, in _check_closed\n raise RuntimeError('Event loop is closed')\nRuntimeError: Event loop is closed\n```\n\nThat's because task executed in thread has finished after loop closing. The task calls `call_soon_threadsafe()` (see `futures.wrap_future()` for details) and it fails on check for loop health.\n\nDue threaded nature it's hard to avoid situations like this: threads cannot be cancelled, we need cope with these even after loop closing. That's pretty common situation, especially for client-side jobs like web page fetching: DNS resolver is executed in thread pool also.\n\nI see two options:\n1. Ignore loop closing in `wrap_future` call, skip `call_soon_threadsafe()` for closed loops\n2. Do the same but only if special boolean flag passed into `run_in_executor()` (while I don't see situations when I don't like the behavior, maybe flag should be `True` by default).\n","author":{"url":"https://github.com/asvetlov","@type":"Person","name":"asvetlov"},"datePublished":"2015-07-26T07:45:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/258/asyncio/issues/258"}
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:84a8265e-d797-fe1f-8186-f5c91c503c4d current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id A7E4:3DFBD6:15A8C42:1E63E3D:696FD0A6 html-safe-nonce 6a1aafe74464f84a95adf276ee789429ddf03d58ff91fe1a179079044349b5cd visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0U0OjNERkJENjoxNUE4QzQyOjFFNjNFM0Q6Njk2RkQwQTYiLCJ2aXNpdG9yX2lkIjoiNjk0NzE2Nzk4ODgzNDM1NzQxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac 714d01626170abe3fb30cc50e1b27537bb98a0a0c115efd7182102211f5bff6d hovercard-subject-tag issue:97295261 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/258/issue_layout twitter:image https://opengraph.githubassets.com/9e1dc1dbc7c83a9c0c239d8f4454ce16c9c0beb867d92fc8508cce4e7c61fbd9/python/asyncio/issues/258 twitter:card summary_large_image og:image https://opengraph.githubassets.com/9e1dc1dbc7c83a9c0c239d8f4454ce16c9c0beb867d92fc8508cce4e7c61fbd9/python/asyncio/issues/258 og:image:alt When I send a long task to tread-pool executor and immediately close the loop without waiting future returned by .run_in_executor() call I get exception report in logs: ERROR:concurrent.futures:exc... og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username asvetlov hostname github.com expected-hostname github.com None 0a44b41159f8508d767a50a41d4355b6e6607de801262664cbe75414886e44e9 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 347f3ebfaef84b36b267c7a20bade84594f267d5 ui-target full theme-color #1e2327 color-scheme light dark
URLs of crawlers that visited me.