Ticket #3205 enhancement new
provide (and encourage) access to the reactor from every event source
|Reported by:||glyph||Owned by:|
Currently if a user wants to access the reactor from a protocol's implementation, they must grab a reference to some global state "from twisted.internet import reactor".
However, it doesn't need to! It already has an object that is talking to reactor: its transport. The protocol should be able to do self.transport.reactor. (e.g) callLater(...).
Now, it just so happens that it can do exactly that; FileDescriptor has a reactor attribute. But it should be a part of the interface, and an encouraged idiom, and used consistently throughout Twisted.
I don't think that we can actually deprecate "from twisted.internet import reactor", but we should do it in a lot fewer places, since it makes testing unnecessarily tricky.
This ticket should probably be resolved when all ITransport implementations in Twisted properly provide this attribute, and it's defined and documented in the interface. However, we also need to file some more tickets for updating the protocol implementations to use it instead.
The same should be true of IDelayedCall, but it is perhaps less idiomatically useful, since IDelayedCall isn't provided to the functions that it's running.