[Twisted-Python] win 32 reactor

Jean-Paul Calderone exarkun at divmod.com
Mon Mar 31 12:55:42 EDT 2008

On Mon, 31 Mar 2008 18:28:09 +0200, Gabriel Rossetti <mailing_lists at evotex.ch> wrote:
>I need to use PyHook, a win32 lib allowing global input monitoring (mouse, 
>keyboard, etc). It uses the PyWin32 extentions, in particular win32com's 
>PumpMessages() function. This is an event loop defined like so :
>// @pymethod |pythoncom|PumpMessages|Pumps all messages for the current 
>thread until a WM_QUIT message.
>static PyObject *pythoncom_PumpMessages(PyObject *self, PyObject *args)
>    MSG msg;
>    int rc;
>    while ((rc=GetMessage(&msg, 0, 0, 0))==1) {
>        TranslateMessage(&msg); // needed?
>        DispatchMessage(&msg);
>    }
>    if (rc==-1)
>        return PyWin_SetAPIError("GetMessage");
>    Py_INCREF(Py_None);
>    return Py_None;
>my question is ho can I make this work with twisted? Is there a way to use 
>the supplied win32 reactors (there are three I think) or do I have to write 
>one myself? Could someone please point me in the right direction?

The three reactors you're probably referring to are selectreactor, win32er,
and IOCP reactor.  Of these, only the latter two do anything particular to
Windows (the first just uses select(2), which Windows sort of has).

win32er is basically a loop around MsgWaitForMultipleObjects.  IOCP reactor
is basically a loop around GetQueuedCompletionStatus.  One way to look at
your question is to consider how GetMessage/TranslateMessage/DispatchMessage
interact with MWFMO and GQCS.  This is basically a Windows API question, so
I can't answer it, since I know very little about Windows APIs.


More information about the Twisted-Python mailing list