Closed vincentbernat closed 3 years ago
Just switching from call_soon(...)
to call_later(0.1, ...)
fixes the issue. However, I am wondering if you could not just append a callback to the scheduled tasks to run or signal the reaper instead of having an active event loop?
The whole reason the TaskKeeper
/_reaper
mechanism exists is because asyncio
does not keep strong refs to the task objects it creates. So they are liable to disappear at unexpected times before they complete. So the TaskKeeper
base class keeps strong refs to created tasks, and the _reaper
callback exists to watch for completed tasks, to get rid of the unneeded task objects.
Yeah, I should probably throttle the frequency at which the _reaper
task runs. Maybe even an interval of 0.25 seconds or a second should be sufficient. Or make it caller-configurable.
Either that, or come up with a more elegant mechanism.
Hey!
After profiling a program, I have noticed that the
_reaper
function is called very often and responsible for some quite CPU usage due to this. From my understanding, it is running at each tick as long as there is a DBus related task running, which is always if you are listening for signals.I would suggest to just sleep a bit inside reaper.