Opened 6 years ago

Last modified 6 years ago

#3205 enhancement new

provide (and encourage) access to the reactor from every event source

Reported by: glyph Owned by:
Priority: high Milestone:
Component: core Keywords:
Cc: Branch:
Author: Launchpad Bug:

Description

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.

Change History (3)

comment:1 Changed 6 years ago by glyph

  • Priority changed from normal to high

Bumping the priority, since this is something that keeps coming up.

comment:2 Changed 6 years ago by glyph

It also occurs to me that this ticket should deal with IListeningPort, IConnector, and perhaps the smattering of various datagram interfaces.

comment:3 Changed 4 years ago by <automation>

  • Owner glyph deleted
Note: See TracTickets for help on using tickets.