Opened 5 years ago

Closed 5 years ago

#4153 enhancement closed duplicate (duplicate)

It should be easier to choose a sane reactor default for a given platform

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

Description

I recently needed the functionality to choose an epoll reactor on Linux, kqueue reactor on bsd, poll reactor on unixes, and select reactor on windows. I looked around a bit in the source and was surprised to find that there was no functionality for doing this easily. I wrote a simple function to do this, and popped on the #twisted IRC channel, where spiv suggested that I open a ticket about this for discussion.

Below is my quickly-written function:

def installCommonReactor():
    try:
        from twisted.internet import kqreactor
        kqreactor.install()
        return
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        pass
    try:
        from twisted.internet import epollreactor
        epollreactor.install()
        return
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        pass
    try:
        from twisted.internet import pollreactor
        pollreactor.install()
        return
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        pass

Notes about this particular implementation: I did it in this way of repeated imports for maximum explicitness. I could envision, however, trading some of that explicitness for flexibility (you could supply a priority list, loop over the list, and dynamically import the reactors that way). Also, I'm not extremely happy with the exception whitelisting, as ImportError would be far and away the most common exception. That being said, I can foresee other errors as well and since this is really about falling back to what reactor works in a given environment, that was the reasoning behind that detail.

Questions: Is this something Twisted is interesting in incorporating at all? What are the thoughts on what an implementation would look like?

Change History (2)

comment:1 Changed 5 years ago by glyph

  • Resolution set to duplicate
  • Status changed from new to closed

This is definitely something we'd like to incorporate! Please join the discussion on #2234 (which I believe this ticket is a duplicate of, so I'm closing it).

Thanks for taking the time to describe this in detail though, I'll be adding a link back to this ticket as well.

comment:2 Changed 4 years ago by <automation>

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