Before I go with python ...

Andrew Csillag andrew at starmedia.net
Wed Dec 29 18:46:52 EST 1999


Paulo da Silva wrote:
> 
> I'm considering to use python after reading
> some docs about it. I have a doubt I couldn't
> get responded until now.
> Is it possible to have assynchronous I/O,
> for example continuing a program while
> another task is wainting on a socket?
> 
> How is taht achieved? Multithread? Just
> a call after the socket has data?
> 
Your choice.  Python can do threads, and if you are on Unix (maybe
windows, but I don't know) you can also use the select module.  With the
select module you can say "let me know if 1) there is data ready for
reading on a 'waitable object' (sockets, files, etc.) 2) a 'waitable
object' is ready to be written to or 3) if there is out-of-band data on
a socket".  You can also set a timeout on the select so if you want to
wait a certain amount of time (or indefinitely) for something to happen,
you can, or you can have it return immediately.  See 
http://www.python.org/doc/current/lib/module-select.html or the
select(2) manpage for details.

Cheers,
Drew
-- 
import string,sys;t=string;f=t.index;j=t.join;print(lambda
s:j(map(lambda
x,s=s:x[:f(x,':')+2]+j(map(lambda y:'%02X'%ord(y),x[f(x,':')+2:]),'
'),map
(lambda i,s=s:("%04X: "%
i)+s[i:i+16],range(0,len(s),16))),'\n'))(open(sys.
argv[1]).read())




More information about the Python-list mailing list