Hi @orf — I hope you don’t mind me pinging you here, I wanted to pick your brain.
(@andrewgodwin cc-ing you here for interest and expertise )
tl;dr — do you think it would be feasible, and do you have any preliminary pointers, for allow the auto-reloader to use subprocess, rather than (or as well as) threading?
More detail
We had an issue with Channels’ runserver not working with the auto-reloader.
The summary is that Daphne/twisted is initialised with the asyncio event loop from the main thread, but then the auto-reloader runs it in a sub-thread, and trouble ensues. (I reduced this here — hopefully you’ll how that’s parallel to the auto-loader situation.)
We patched that in Daphne, giving twisted it’s own event loop to work with.
That seemed to work but caused a number of unrelated issues. Essentially folks all use get_event_loop()
expecting to get A) the event loop from the main thread, and B) the event loop Daphne/twisted is running (which, the expectation is, will be the same.) When that’s not true, things break. (Related issues: daphne#332, daphne#319, daphne#299)
I’m going to have to revert the original fix — but that means no auto-reload support, at least for now.
The solution would be if the auto-reloader would spin up Daphne as a subprocess, rather than a thread. That way it gets to run in the main thread, and everyone is happy.
Can I ask for initial thoughts on the plausibility of such?
Thanks!