[Tutor] using select
Denis Dzyubenko
shad@mail.kubtelecom.ru
Thu Jun 19 05:28:47 2003
Hello, all python programmers!
In my python-program I used poll() function, but I noticed that poll()
is not accessible under Windows, so I changed this code:
...
POLL_TIMEOUT = 10
...
fd = select.poll()
fd.register(sfdcl, select.POLLIN | select.POLLPRI)
while len(fd.poll(POLL_TIMEOUT)) > 0:
p = sfdcl.recvfrom(self.getmsgsize())
...
with this one:
...
while len(select.select([sfdcl],[],[],POLL_TIMEOUT/1000.0)[0]) > 0:
p = sfdcl.recvfrom(self.getmsgsize())
...
It works just fine, but I have never worked with sockets (and
select(),poll() functions), so I am not sure if this code is
correct. Where can I read docs about sockets and select/poll (I have
already read man pages) ?
Then, my program must wait input from socket and from stdin, now I do
this using select() that waits for data in two file descriptiors
(sys.stdin and 'sfdcl' - my socket), but I noticed that windows
doesn't support select() with file descriptors, only sockets are
acceptable. What should I do? Can threads help me - for example one
thread reads from stdin, and another - from socket ?
Thanks for your help!
--
Denis.
P.S. Sorry for terrible english, it is not my native language :(