How to make socket.recv(500) not stop a while loop.

Posted by ImTooStupidForThis on Stack Overflow See other posts from Stack Overflow or by ImTooStupidForThis
Published on 2010-03-14T19:13:18Z Indexed on 2010/03/14 19:15 UTC
Read the original article Hit count: 122

Filed under:
|
|

I made an IRC bot which uses a while true loop to receive whatever is said.
To receive I use recv(500), but that stops the loop if there isn't anything to receive, but i need the loop to continue even if there isn't anything to receive.
I need a makeshift timer to continue running.

Example code:

/A lot of stuff/
timer=0
while 1:
    timer=timer+1
    line=s.recv(500) #If there is nothing to receive, the loop and thus the timer stop.
/A lot of stuff/

So either I need a way to stop it stopping the loop, or I need a better timer.

© Stack Overflow or respective owner

Related posts about python

Related posts about while