On Jan 28, 2025, at 8:23 AM, km@krot.org wrote:
Thank you for detailed feedback!
Thanks for the questions! These are nuances that are difficult to capture in the documentation, even if it were excellent (and it isn't).
So I understand that although I write code in a non-synchronous way, some parts trigger the code running immediately.
Exactly. This is a conscious decision, because it allows the state to be affected immediately, which can make certain sorts of testing easier, but a subtle one.
so ReactorNotRunning can be raised both when reactor is not yet running, but also when it is running, but stop has been called?
A bool which is True from during startup to during shutdown and False the rest of the time.
Now, `stop`'s documentation
https://docs.twistedmatrix.com/en/stable/api/twisted.internet.interfaces.IReactorCore.html#stop is missing the explanation of when ReactorNotRunning is raised, and we should fix that. But the intention behind this exception is that if you call .stop() when its behavior might not do anything or might do something unexpected, it raises an exception so you can debug this problem with lifecycle state. There are shutdown hooks that your code might expect to run (such as those with addSystemEventTrigger) and so managing these expectations and getting loud errors is important, because otherwise you get a lot of "the reactor just didn't exit" bugs that are harder to observe.
Thanks again,
-g