sockets - sleep() function (python) -


  if data.find('!google') != -1:      nick = data.split('!')[ 0 ].replace(':','')      try:        gs = googlesearch(args)        gs.results_per_page = 1        results = gs.get_results()        res in results:          sck.send('privmsg ' + chan + " " + res.title.encode("utf8") + '\r\n')          sck.send('privmsg ' + chan + " " + res.url.encode("utf8") + '\r\n')          print      except searcherror, e:        sck.send('privmsg ' + chan + " " + "search failed: %s" % e + " " + '\r\n') 

ok i'm trying make script wait few seconds before user can "!google" prevent users flooding channel or bot, not sure if should use sleep() function because might stop whole script, want make wait few seconds before can use "!google" again.

there sleep function inside time module.

however, make script not block, can call time function in time module , store that. if current time less plus, say, 5 seconds, don't allow them use it.

for example:

last_google = 0 # somewhere later in script last_google still in scope... if data.find('!google') != -1:     if last_google + 5 < time.time():         # throttled         return     last_google = time.time()     # here 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -