crochet icon indicating copy to clipboard operation
crochet copied to clipboard

ResultRegistry has its stop method called before shutdown

Open habnabit opened this issue 10 years ago • 1 comments

That is,

        self._reactor.addSystemEventTrigger(
            "before", "shutdown", self._registry.stop)

I'm running into an issue now where I'm trying to process HTTP requests during reactor shutdown (a deferred was returned from a 'before shutdown' callback that fires when all HTTP requests are done), and some of the HTTP request processing uses crochet eventual results. Because the registry is stopped before shutdown, some of the HTTP requests die with a ReactorStopped error during processing.

habnabit avatar May 29 '14 19:05 habnabit

I actually moved this from after shutdown to before shutdown as a fix for #17. The problem in general is that Twisted adds these events in the order addSystemEventTrigger is called, rather than the more useful reverse order (as e.g. TestCase.addCleanup does I believe). The problem in the specific is Twisted's ThreadPool doing thread joins waiting for them all to stop as part of shutdown, which is rather annoying.

Any ideas for solutions that address both use cases? A workaround is for your code to call addSystemEventTrigger first, but that's not great. Perhaps Twisted should move ThreadPool shutdown to the "after" phase, and then crochet registry shutdown can happen in the "during" phase... the whole shutdown process is hacky.

Lacking any good ideas I'm not going to put anything in the release I'm about to do.

itamarst avatar May 31 '14 19:05 itamarst