[python-win32] win32event.WaitForMultipleObjects and sockets

Amaury Forgeot d'Arc amauryfa at gmail.com
Thu May 26 11:05:32 CEST 2011


2011/5/26 David Markey <admin at dmarkey.com>:
> Hi All,
> Sorry for the n00b question...
> With win32event.WaitForMultipleObjects, I dont seem to be able to give it a
> plain socket object. How can I create a PyHANDLE from a socket?

It won't work like this, because a socket has several things you
can wait for (available for read, available for write, accept, error,
and probably others)

You should use WSAEventSelect() to associate a socket with a handle.

This is pseudo-code (I don't have Windows at the moment, sorry)::

    socket_event = WSACreateEvent()
    WSAEventSelect(mysocket, socket_event, FD_READ | FD_CLOSE)
    ... then socket_event may be used in WaitForMultipleObjects...
    WSACloseEvent(socket_event)


-- 
Amaury Forgeot d'Arc


More information about the python-win32 mailing list