`AsyncIOExecutor` and class-based job callbacks
See original GitHub issueIs your feature request related to a problem? Please describe. I have a class along the lines
class MyTask:
...
(async) def __call__(self, *args, **kwargs):
....
and use this as job callback via scheduler.add_job(MyTask(), **job_kwargs)
. This works fine on 3.x with BackgroundScheduler
. However, when using AsyncIOScheduler
, when the job runs, asyncio
will issue a warning about MyTask.__call__
not having been awaited.
This is due to util.iscoroutinefunction
returning False
for MyTask()
in AsyncIOExecutor._do_submit_job
:
Describe the solution you’d like
Add support for passing callable non-function-objects as callbacks to AsyncIOScheduler
by modifying util.iscoroutinefunction
to something like
def iscoroutinefunction_partial(f):
while isinstance(f, partial):
f = f.func
return iscoroutinefunction(f) or (hasattr(f, '__call__') and iscoroutinefunction(f.__call__))
This does the trick.
Describe alternatives you’ve considered TBH, I don’t see any alternative solutions for this in terms of what APS could do. Ofc an alterantive would be for me to re-design my scheduling. That’s probably feasible and not too hard. But this use case seemed reasonable enough for me to open an issue 🙃
Additional context If there is a chance for another 3.x release and you would be okay with including this, I’m happy to try & PR with the solution proposed above. I’m aware that development is currently headed for v4. I haven’t tried finding out if this is an issue on v4 as well or how it could be supported. If you agree with adding support for is in general, I can try to investigate v4 in this regard.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top GitHub Comments
I think it would be reasonable to assume that this should work. I will add a test to ensure that it does.
Is there any follow-up on this issue?