Reputation: 3981
I'm researching the asyncio library and I cannot understand completely the reason behind event loop policies.
So far it's clear that this interface is a factory that returns event loop for current context. The definition of the context is not clear though. Apparently, the interface of asyncio.AbstractEventLoopPolicy assumes that concrete implementation will be able to extract context on its own because neither method accepts arguments. This model works well for the event-loop-per-thread default policy, but usage under more sophisticated circumstances are under the question.
Looks like context isn't an arbitrary entity, but should follow certain rules (e.g. being visible globally). I wonder if such rules are listed anywhere. Are there examples of custom policies around?
Upvotes: 2
Views: 1136
Reputation: 17376
Custom policy is required when you implement non-default event loop.
The main problem is: I want to create new event loop by asyncio.new_event_loop()
. It's required for threads: only main thread has implicit event loop, all other threads should instantiate loop explicitly.
But I don't know specific event loop type, thus I need a factory for loop creation -- pluggable event loop policy.
Upvotes: 2