Repository navigation
#12514 Fix MemoryReactor.callWhenRunning not invoking callbacks if already started - #12514
Conversation
CodSpeed Performance ReportMerging #12514 will not alter performanceComparing Summary
|
| if self.running: | ||
| callable(*args, **kw) | ||
| return None |
There was a problem hiding this comment.
Should we additionally append to self.whenRunningHooks in this case?
I'm guessing we may want to always append to self.whenRunningHooks to avoid breaking people's tests that rely on this behavior 🤷
As an aside, it's weird that we will invoke the hooks multiple times whenever reactor.run() is called because we never clear out self.whenRunningHooks
There was a problem hiding this comment.
I think that whenRunningHooks should have been private and people should not depend on it.
Also... when reactor.run() is called, I think that whenRunningHooks should be cleared...
I don't know what to say.
My call is to go with this implementation...and we can see if people will complain
| if self.running: | ||
| callable(*args, **kw) | ||
| return None | ||
| else: | ||
| self.whenRunningHooks.append((callable, args, kw)) |
There was a problem hiding this comment.
For reference, this matches the ReactorBase.callWhenRunning implementation:
twisted/src/twisted/internet/base.py
Lines 893 to 905 in ef6160a
|
please review
|
There was a problem hiding this comment.
Hi Eric.
Thanks for the fix. Much appreciated
Changes looks good.
I left a few minor comments.
From the interface documentation I see
Call a function when the reactor is running.
If the reactor has not started, the callable will be scheduled to run when it does start. Otherwise, the callable will be invoked immediately.
Co-authored-by: Adi Roiban <[email protected]>
See #18903 (comment) --- Related to twisted/twisted#12514
MemoryReactor.callWhenRunning not invoking callbacks if already startedMemoryReactor.callWhenRunning not invoking callbacks if already started
|
Thanks for the review and merge @adiroiban 🙂 |
Fix
MemoryReactor.callWhenRunningnot invoking callbacks if already started(noticed while working on element-hq/synapse#18903)
Scope and purpose
Previously,
MemoryReactor.callWhenRunningwouldn't invoke any of the callbacks if the reactor had already started. It did invoke callbacks collected before the reactor started running.The interface,
IReactorCore.callWhenRunning, describes how it should be behaving:twisted/src/twisted/internet/interfaces.py
Lines 1475 to 1491 in ef6160a
This also matches how
ReactorBaseimplements things:twisted/src/twisted/internet/base.py
Lines 893 to 905 in ef6160a
Related to #3025
Dev notes
https://docs.twisted.org/en/latest/development/dev-process.html
Contributor Checklist:
This process applies to all pull requests - no matter how small.
Have a look at our developer documentation before submitting your Pull Request.
Below is a non-exhaustive list (as a reminder):
please review.Our bot will trigger the review process, by applying the pending review label
and requesting a review from the Twisted dev team.