[Twisted-Python] knowing which reactor is running

L. Daniel Burr ldanielburr at mac.com
Mon Oct 23 15:04:32 EDT 2006

On Mon, 23 Oct 2006 13:48:18 -0500, Manlio Perillo  
<manlio_perillo at libero.it> wrote:

> Jean-Paul Calderone ha scritto:
>> On Sat, 21 Oct 2006 12:11:29 +0200, Manlio Perillo
>> <manlio_perillo at libero.it> wrote:
>>> In a test suite I need to know if the win32eventreactor is running.
>>> Any solution?
>> You generally shouldn't need this information.  Rather, you should rely
>> on the interfaces provided by the reactor you're using, and less  
>> commonly
>> the modules which you are able to import.
> But the win32eventreactor does not implement a "special" interface like,
> say, IWin32EventReactor.
> Regards  Manlio Perillo
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Of course it doesn't, because interfaces aren't types.  Having an
interface named IWin32EventReactor makes no sense, because the
whole point of interfaces is to describe how something acts, not
what it is.  Types answer the question "what is this?"; interfaces
answer the question "what can I do with this?".

What exarkun is getting at is this: You shouldn't need to know what
*type* of reactor you have.  Instead, you should find out what kind
of behaviors your reactor instance supports, and interfaces are a
good way to do that.

This is really similar to the case with JavaScript and browser-sniff
strategies.  It used to be that most libraries relied on sniffing the
user-agent string to determine what browser they were dealing with.
Over time, it has become more common to test for supported behavior,
e.g., checking for document.implementation, etc.

Hope this helps,

L. Daniel Burr

More information about the Twisted-Python mailing list