#6147 enhancement new
public API for initializing the reactor when a main loop is already running
|Reported by:||glyph||Owned by:|
Sometimes, you run the loop, and sometimes, the loop runs you.
Specifically, sometimes you are writing a full program with a main() and everything, and sometimes you are writing a plugin for a program that is already running a main loop; many GUI programs, especially, support Python plugins.
It should be possible to use Twisted from within a program that is already using a supported main loop (i.e. GTK, CF, QT). Implementation wise, this is usually quite a simple proposition: for example, in _glibbase, this could be easily made to work by moving the self.callWhenRunning(self._reschedule) into startRunning instead of run, and then calling reactor.startRunning(). (In fact I believe this used to work at some point in the past.)
However, to be a supported API, a bit more is necessary; it should be easy to safely use such an API cooperatively so that multiple plugins may attach themselves to the same reactor without attaching two reactor instances to the same loop or raising exceptions because a reactor is already installed.
Each reactor foreign event-loop module will need some implementation of such an interface, but just to be clear about the scope of this ticket, it should be closed by a change where the interface is specified and at least one reactor implements it; we should file a ticket for the others.