win32: emulating select() on pipes

G

gangesmaster

hi

i'm trying to figure out if a pipe on win32 has data for me to read.
this is the code i've come up with:

def poll(self, timeout, interval = 0.2):
"""a poor man's version of select() on win32"""
from win32pipe import PeekNamedPipe
from msvcrt import get_osfhandle

handle = get_osfhandle(self.fileno())
if timeout is None:
timeout = sys.maxint
length = 0
tmax = time.time() + timeout
while length == 0 and time.time() < tmax:
length = PeekNamedPipe(handle, 0)[2]
time.sleep(interval)
return length != 0

does anyone know of a better way to tell if data is available on a
pipe?
something that blocks until data is available or the timeout is
elapsed,
and returns True if there's something for me to read, or False
otherwise.


-tomer
 
B

Bryan Olson

gangesmaster said:
i'm trying to figure out if a pipe on win32 has data for me to read. [...]

does anyone know of a better way to tell if data is available on a
pipe?
something that blocks until data is available or the timeout is
elapsed,

In Win32 WaitForMultipleObjects and WaitForMultipleObjectsEx do
that, for up to 64 objects. In the Hammond Win32 extension
package, they're exported by win32event.

If 64 pipes in one call isn't enough, there are completion ports.
CreateIoCompletionPort is in win32file.

A third way in Win32 is WriteFileEx and a completion routine,
but it looks like the extension module doesn't support it.

I have not used the functions from the Hammond package, and
I notice the doc strings are None. You can probably figure
the wrappers out by reading the Microsoft documentation and
trying stuff. And of then there's the source.

If you put together a simple working example, I hope you'll
post it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top