Opened 9 years ago

Last modified 21 months ago

#1616 enhancement new

interface to query reactor name

Reported by: exarkun Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch:
Author: Launchpad Bug:

Description

it is a somewhat common use-case to launch a new process which uses twisted. often this new process should use the same reactor as the process which is launched it. currently, some nasty assumptions need to be made in order to do this. there should be a simple, documented way.

Change History (7)

comment:1 Changed 6 years ago by exarkun

http://bazaar.launchpad.net/~ghtdak/qt4reactor/trunk/annotate/head%3A/qt4reactor.py#L13 suggests a novel solution to this feature request:

from twisted.application import reactors
reactors.installReactor(name)

comment:2 Changed 6 years ago by exarkun

Ah, of course, that's only half of a solution. You still need a way to find out the name of a given reactor.

comment:3 Changed 4 years ago by <automation>

  • Owner itamarst deleted

comment:4 Changed 4 years ago by exarkun

  • Keywords easy added

comment:5 Changed 2 years ago by dannyobrien

I may just be making the nasty assumptions more explicit in this, but this seems to be the best way to return the name of the current reactor:

<pre>
from twisted.internet import selectreactor
selectreactor.install()
from twisted.internet import reactor
from twisted.application import reactors

def getShortname(reactor):

for reactor_installer in reactors.getReactorTypes():

if reactor_installer.moduleName == reactor.module:

return reactor_installer.shortName

return None

</pre>

The assumption is mainly that the current reactor is listed in the installable reactors list in twisted.application.reactors. Hanging this method off the standard reactor interface would mean pulling in the reactors module; it might make sense to place it in with the other methods in twisted.application.reactors.

Not sure whether we can come up with a canonical way to pass this to another process that's running its own reactor.

comment:6 Changed 2 years ago by dannyobrien

That's to say:

from twisted.internet import selectreactor
selectreactor.install()
from twisted.internet import reactor
from twisted.application import reactors


def getShortname(reactor):
    for reactor_installer in reactors.getReactorTypes():
        if reactor_installer.moduleName == reactor.__module__:
            return reactor_installer.shortName
    return None

comment:7 Changed 21 months ago by itamar

  • Keywords easy removed
Note: See TracTickets for help on using tickets.