sockets question

Artificial Life phark52 at yahoo.com
Sat Feb 26 00:40:30 EST 2005


On Sat, 26 Feb 2005 00:35:57 -0500, Mohammed Smadi wrote:

> hi;
> 
> i have the following piece of code:
> =============
> s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
> s.bind(("",port))
> s.sendto(data,(MY_GW,port)) 
> data = s.recvfrom(1024)  
> ============
> 
> data contains some instructions which i am sending to MY_GW.  If the 
> reply arrives from the MY_GW quickly then things fine, otherwise the 
> program is going to freeze waiting for the reply.  I want to do the 
> following:
> 
> 1- Be able to impose a timeout after which i want to stop executing 
> the s.recvfrom statement.
> 
> rgds;
> m.smadi


That happens because those functions 'block.' Search for Non-blocking
sockets, and the 'select' module




More information about the Python-list mailing list