add --loop-factory module:callable to the worker and scheduler CLI
resolve and validate the configured factory before creating an event loop
resolve worker factories inside each worker subprocess
let an explicit worker factory override automatic uvloop selection
preserve existing behavior when no factory is configured
document the option for both commands
Motivation
Some integrations require a specific event loop implementation. For example, async Psycopg on Windows requires a selector-based loop instead of the default ProactorEventLoop.
Applications can currently influence TaskIQ-created loops through process-wide asyncio policies, but those policies are deprecated in Python 3.14 and scheduled for removal in Python 3.16.
This provides a generic application-controlled mechanism and a forward-compatible alternative for the Windows compatibility case discussed in #641, without changing TaskIQ's default loop on any platform.
Compatibility
The scheduler uses AnyIO's loop_factory backend option so the feature remains compatible with TaskIQ's Python 3.10 minimum. The worker keeps its existing loop lifecycle and changes only how the loop is selected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #659.
Summary
Motivation
Some integrations require a specific event loop implementation. For example, async Psycopg on Windows requires a selector-based loop instead of the default ProactorEventLoop.
Applications can currently influence TaskIQ-created loops through process-wide asyncio policies, but those policies are deprecated in Python 3.14 and scheduled for removal in Python 3.16.
This provides a generic application-controlled mechanism and a forward-compatible alternative for the Windows compatibility case discussed in #641, without changing TaskIQ's default loop on any platform.
Compatibility
The scheduler uses AnyIO's loop_factory backend option so the feature remains compatible with TaskIQ's Python 3.10 minimum. The worker keeps its existing loop lifecycle and changes only how the loop is selected.