-
Notifications
You must be signed in to change notification settings - Fork 554
Add async task background worker #4591
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: srothh/worker-class-hierarchy
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## srothh/worker-class-hierarchy #4591 +/- ##
=================================================================
- Coverage 84.98% 84.48% -0.51%
=================================================================
Files 158 158
Lines 15414 15516 +102
Branches 2432 2448 +16
=================================================================
+ Hits 13100 13108 +8
- Misses 1561 1654 +93
- Partials 753 754 +1
|
1261319
to
2896602
Compare
7ada4b3
to
1a129f7
Compare
2896602
to
268ea1a
Compare
1a129f7
to
97c5e3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great work. I have some comments for improvement.
1fbf85f
to
ef780f3
Compare
Add a new implementation of the worker interface, implementing the worker as an async task. This is to be used by the upcoming async transport. GH-4581
Refactor the flush method in the async worker to use the async_flush coroutine. GH-4581
…unctions Add a check to see wheter callbacks are awaitable coroutines or functions, as coroutines need to be awaited. GH-4581
…coroutines Coroutines do not return None, therefore it is necessary to consider this in the callback parameter of the worker. Previously, only callbacks with return Type None were accepted. GH-4581
Enable concurrent callbacks on async task worker by firing them as a task rather than awaiting them. A done callback handles the necessary queue and exception logic. GH-4581
Changed kill to also use the _TERMINATOR sentinel, so the queue is still drained to this point on kill instead of cancelled immediately. This should also fix potential race conditions with flush_async. GH-4581
Add proper type annotation to worker task list to fix linting problems GH-4581
Refactor worker implementation to simplify callback processing, fix pending calculation and improve queue initialisation. GH-4581
97c5e3d
to
b5eda0e
Compare
The flush method in the transport enqueues a sync callback for the worker, therefore the check needs to be here after all. GH-4581
The callbacks passed to the worker from the transport are all async now, so this is currently not needed. GH-4581
CI lint issue is in an unrelated file, not sure why it is popping up. |
Add a new implementation of the transport background worker based on an async task. This worker mostly mirrors the same functionality as the thread-based worker, with the exception that it exposes a non-blocking async flush (which can be awaited from an async context). Furthermore, the worker itself is not thread-safe and should be called using run_coroutine_threadsafe or similar when called from another thread (this is fixed and handled by the transport). I have kept the fork check from the threaded worker, but I am not sure if it is necessary as forking in an async application would also break the event loop.
GH-4581