[Twisted-Python] knowing which reactor is running

In a test suite I need to know if the win32eventreactor is running. Any solution? Thanks and regards Manlio Perillo

El Sábado, 21 de Octubre de 2006 07:11, Manlio Perillo escribió:
In a test suite I need to know if the win32eventreactor is running. Any solution?
I'm new to python and twisted but try: print reactor.__class__ Y get something like: reactor class: <class 'twisted.internet.selectreactor.SelectReactor'> probably win32eventreactor will say something like: reactor class: <class 'twisted.internet.win32eventreactor.XXX'> Greetings PS:I'm using GNU/Linux, can't try further. -- Nicolás D. César <ncesar@lunix.com.ar> Lunix S.R.L. -[ http://www.lunix.com.ar ]- GnuPG Public Key: gpg --keyserver wwwkeys.pgp.net --recv-key 0x3606F3E6

On Sat, 21 Oct 2006 12:11:29 +0200, Manlio Perillo <manlio_perillo@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. Jean-Paul

On Mon, 23 Oct 2006 13:48:18 -0500, Manlio Perillo <manlio_perillo@libero.it> wrote:
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

Hi Manlio, On Mon, 23 Oct 2006 14:27:03 -0500, Manlio Perillo <manlio_perillo@libero.it> wrote:
An IWin32Event interface would suggest support for the win32 event system, but adding "Reactor" to the end of that is wrong, in my opinion. Naming conventions aside, yes, you have the right idea. You'd check your reactor instance to see if it supports the IWin32Event interface, rather than checking the instance's class name.
Regards Manlio Perillo
Hope this helps, L. Daniel Burr

L. Daniel Burr ha scritto:
Hi Manlio,
Hi.
You are right, I just picked up the first name that come to my mind.
When I find some time I will write a ticket. Moreover I think that a one more ticked is needed for polishing the little mess (IMHO) with abstract.FileDescriptor, what it is used in _win32serialport and _pollingfile. As an example: 1. abstract.FileDescriptor for Posix file descriptors (like sockets) 2. win32handle.Win32Handle for win32 handles that can get notified by WaitForSingleObject and friends (like input console and generic events) 3. upoll.PollableResource for "poor man" polling Regards Manlio Perillo

El Sábado, 21 de Octubre de 2006 07:11, Manlio Perillo escribió:
In a test suite I need to know if the win32eventreactor is running. Any solution?
I'm new to python and twisted but try: print reactor.__class__ Y get something like: reactor class: <class 'twisted.internet.selectreactor.SelectReactor'> probably win32eventreactor will say something like: reactor class: <class 'twisted.internet.win32eventreactor.XXX'> Greetings PS:I'm using GNU/Linux, can't try further. -- Nicolás D. César <ncesar@lunix.com.ar> Lunix S.R.L. -[ http://www.lunix.com.ar ]- GnuPG Public Key: gpg --keyserver wwwkeys.pgp.net --recv-key 0x3606F3E6

On Sat, 21 Oct 2006 12:11:29 +0200, Manlio Perillo <manlio_perillo@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. Jean-Paul

On Mon, 23 Oct 2006 13:48:18 -0500, Manlio Perillo <manlio_perillo@libero.it> wrote:
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

Hi Manlio, On Mon, 23 Oct 2006 14:27:03 -0500, Manlio Perillo <manlio_perillo@libero.it> wrote:
An IWin32Event interface would suggest support for the win32 event system, but adding "Reactor" to the end of that is wrong, in my opinion. Naming conventions aside, yes, you have the right idea. You'd check your reactor instance to see if it supports the IWin32Event interface, rather than checking the instance's class name.
Regards Manlio Perillo
Hope this helps, L. Daniel Burr

L. Daniel Burr ha scritto:
Hi Manlio,
Hi.
You are right, I just picked up the first name that come to my mind.
When I find some time I will write a ticket. Moreover I think that a one more ticked is needed for polishing the little mess (IMHO) with abstract.FileDescriptor, what it is used in _win32serialport and _pollingfile. As an example: 1. abstract.FileDescriptor for Posix file descriptors (like sockets) 2. win32handle.Win32Handle for win32 handles that can get notified by WaitForSingleObject and friends (like input console and generic events) 3. upoll.PollableResource for "poor man" polling Regards Manlio Perillo
participants (4)
-
Jean-Paul Calderone
-
L. Daniel Burr
-
Manlio Perillo
-
Nicolas D. Cesar