Title: Dataloader in multi-threaded environments · Issue #71 · graphql-python/graphql-core · GitHub
Open Graph Title: Dataloader in multi-threaded environments · Issue #71 · graphql-python/graphql-core
X Title: Dataloader in multi-threaded environments · Issue #71 · graphql-python/graphql-core
Description: Hi, I've been thinking a bit about how we could implement the Dataloader pattern in v3 while still running in multi-threaded mode. Since v3 does not support Syrus's Promise library, we need to come up with a story for batching in async m...
Open Graph Description: Hi, I've been thinking a bit about how we could implement the Dataloader pattern in v3 while still running in multi-threaded mode. Since v3 does not support Syrus's Promise library, we need to come...
X Description: Hi, I've been thinking a bit about how we could implement the Dataloader pattern in v3 while still running in multi-threaded mode. Since v3 does not support Syrus's Promise library, we need...
Opengraph URL: https://github.com/graphql-python/graphql-core/issues/71
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Dataloader in multi-threaded environments","articleBody":"Hi, \r\n\r\nI've been thinking a bit about how we could implement the Dataloader pattern in v3 while still running in multi-threaded mode. Since v3 does not support Syrus's [Promise library](https://github.com/syrusakbary/promise), we need to come up with a story for batching in async mode, as well as in multi-threaded environments. There are many libraries that do not support `asyncio` and there [are many cases](https://techspot.zzzeek.org/2015/02/15/asynchronous-python-and-databases/) where it does not make sense to go fully async. \r\n\r\nAs far as I understand, the only way to batch resolver calls from a [single frame of execution](https://github.com/graphql/dataloader/blob/master/src/index.js#L220-L222) would be to use [`loop.call_soon`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.call_soon). But since `asyncio` is [not threadsafe](https://docs.python.org/3/library/asyncio-dev.html#concurrency-and-multithreading), that means we would need to run a separate event loop in each worker thread. We would need to wrap the `graphql` call with something like this:\r\n\r\n```py\r\ndef run_batched_query(...):\r\n loop = asyncio.new_event_loop()\r\n execution_future = graphql(...)\r\n loop.run_until_complete(result_future)\r\n return execution_future.result()\r\n```\r\n\r\nIs that completely crazy? If yes, do you see a less hacky way? I'm not very familiar with `asyncio` so I would love to get feedback.\r\n\r\nCheers\r\n","author":{"url":"https://github.com/jnak","@type":"Person","name":"jnak"},"datePublished":"2019-12-09T23:33:55Z","url":"https://github.com/graphql-python/graphql-core/issues/71"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:521f6c30-7b66-fe8a-bdbb-d7afb72cf6a0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9386:2DB972:192998E:2058703:6AFFB855 |
| html-safe-nonce | 8eb0ea41ff6ef94f10f1025bc44fb1dcbf987737233bd46c4277eef1dff1e0de |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Mzg2OjJEQjk3MjoxOTI5OThFOjIwNTg3MDM6NkFGRkI4NTUiLCJ2aXNpdG9yX2lkIjoiODUyNTgxNjMwNjkzMzQxMzk3MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6dca97e847de35acf816ce39bf6c8b46508f13601a16f812af038c4012eb511f |
| hovercard-subject-tag | issue:535400876 |
| 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/graphql-python/graphql-core/71/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d1b2a95ae130f8b445ac01eab6c99f9bdfa79bcd2f8a498a1e43f9881ef0fed3/graphql-python/graphql-core/issues/71 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d1b2a95ae130f8b445ac01eab6c99f9bdfa79bcd2f8a498a1e43f9881ef0fed3/graphql-python/graphql-core/issues/71 |
| og:image:alt | Hi, I've been thinking a bit about how we could implement the Dataloader pattern in v3 while still running in multi-threaded mode. Since v3 does not support Syrus's Promise library, we need to come... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jnak |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7e461843db1c75e40d788c5cfd440d0e4ae1271cf19e06a798d0e7feb2d708f3 |
| turbo-cache-control | no-preview |
| go-import | github.com/graphql-python/graphql-core git https://github.com/graphql-python/graphql-core.git |
| octolytics-dimension-user_id | 15002022 |
| octolytics-dimension-user_login | graphql-python |
| octolytics-dimension-repository_id | 143207933 |
| octolytics-dimension-repository_nwo | graphql-python/graphql-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 143207933 |
| octolytics-dimension-repository_network_root_nwo | graphql-python/graphql-core |
| 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 | d29a6a99861646939301302fab465f9f123b4773 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width