-
-
Notifications
You must be signed in to change notification settings - Fork 484
refactor: keep iterator on the main thread #4432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor: keep iterator on the main thread #4432
Conversation
- reuse `stream_event` dictionary
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4432 +/- ##
=======================================
Coverage 97.83% 97.84%
=======================================
Files 296 296
Lines 15286 15287 +1
Branches 1711 1712 +1
=======================================
+ Hits 14955 14957 +2
Misses 189 189
+ Partials 142 141 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Can you explain this change a bit more? Where is something handed off to a different thread? |
|
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4432 |
Originally, we start async with create_task_group() as task_group:
task_group.start_soon(partial(self._stream, send))
await self._listen_for_disconnect(cancel_scope=task_group.cancel_scope, receive=receive)If a user, who holds the reference to the iterator, tries to do something with it, Python raises a |
Description
To prevent cross-thread reference errors with
Streamiterators, we keep iterators on the main context and listen for a disconnect asynchronously instead of vice versa.I have properly split the changes into 3 separate commits for better diffs.
Other changes
stream_eventdictionary to avoid recreating the dictionary on every iteration.AsyncIterablecoversAsyncIteratortoo.chain(self.cookies, cookies or ())