-
Notifications
You must be signed in to change notification settings - Fork 69
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
Allow directly instantiating the Scheduler class #69
Comments
I'm not ready to make the decision now. Sorry, I'm overwhelmed with adding strong type annotations to aiohttp. |
Strong type annotations in aiohttp sounds excellent, keep up the good work :) It's ok, I'm in no big hurry. |
I have the same question too. After digging a little bit into the codes, I'm wondering why Lines 16 to 24 in 90dd282
|
Well, technically the scheduler can be instantiated directly in constructor but it should have a check for running event loop like here: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/client.py#L206 |
@asvetlov Thanks for the response. However, I've tried but still not fully understand why it's necessary to be async to perform checks against the running loop. The link you provided is inside a constructor which is also a synchronized behavior. Can you explain a bit more about this? Maybe provide an example for me to show what is actually checked against the loop and the check is performed in async way. Many thanks! |
Please start by reading the following discussion: https://discuss.python.org/t/discussion-or-tracking-tickets-for-move-to-asyncio-get-running-loop/2976 |
Oh, I got it. It's all about to ensure a running loop when initiating a scheduler. Since Thank you very much for the link and the nice work on asyncio, @asvetlov. |
Welcome! |
I suspect we could make this change now. The loop is no longer passed explicitly, and the |
Documentation says:
However I don't understand why this restriction. In the age of type checking, it makes usage of this scheduler weird, because you cannot have
await
in another class'__init__
, which means that you have to defer creating a Scheduler object as a member of an object until later.For example:
Instead I would like to be able to instantiate Scheduler directly, perhaps add a start() async method to it to allow for any future async initialisation that might be needed:
To make this work, all we would need would be a simple PR that:
async def start(): pass
method to Scheduler;Does that sound acceptable?
The text was updated successfully, but these errors were encountered: