title: IRC bot make loop sleep without interrup the main loop
body: <p>i been trying to code an IRC bot, while i have succeed. I am having problems implementing something i want to do. the code works fine, but i have issues in the following:</p>
  
  <p>since the bot uses a While loop to read commands from the IRC when i add a second While with a time.sleep(seconds) the bot does not connect because it reads my second loop and pauses the connection not in time to response the :PING do it disconnects. i been searching but the mor ei search the more confused i get because i don't know what should i try.</p>
  
  <p>stackless, multithreads, subprocess. there are so many results that i just get more confused. so what would be the best method i am trying an RSS bot the bot works fine if i use the command !rss in the IRC channel but i need it to check for new ones ever 10 minutes and if use a sleep command the main loop messes up.</p>
  
  <p>here is my code:</p>
  
  <pre><code>#!/usr/bin/python
  
  import socket, sys, string, time, feedparser, hashlib
  port = 6667
  nick = "RSSbot"
  host = 'irc.server.com'
  name =  "RSSBOT"
  channel = '#debug'
  ident = 'rssbot'
  irc = socket.socket()
  irc.connect ( (host, port) )
  irc.send ( 'NICK ' + nick + '\r\n' )
  irc.send ( 'USER ' + ident + ' ' +  ident + ' ' + ident + ' :rssbot\r\n' )
  
  def readRss():
      feedurl = feedparser.parse("http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=username")
      newest = feedurl['items'][0].title
      newest = newest.replace("username:","")
      msg = newest.split("http://")
      title = msg[0]
      url = msg[1]
      url = "http://" + url
      e = feedurl.entries[2]
      threadurl = e.link
      id = hashlib.md5(url + title).hexdigest()
      irc.send ("PRIVMSG #debug :Tittle:%s\r\n" % newest)
      irc.send ("PRIVMSG #debug :URL: %s\r\n" % url)
      irc.send ("PRIVMSG #debug :MD5: %s\r\n" % id)
  while 1:
      data = irc.recv ( 1024 )
      print(data)
  
      if data.find ( '376' ) != -1:
          irc.send( 'JOIN ' + channel + '\r\n' )
      if data.find ( 'PING' ) != -1:
          irc.send( 'PONG ' + data.split() [1] + '\r\n')
      if data.find ( '!rss' ) != -1:
          feedurl = feedparser.parse("http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=username")
          newest = feedurl['items'][0].title
          newest = newest.replace("username:","")
          msg = newest.split("http://")
          title = msg[0]
          url = msg[1]
          url = "http://" + url
          #e = feedurl.entries[2]
          #threadurl = e.link
          id = hashlib.md5(url + title).hexdigest()
          irc.send ("PRIVMSG #debug :Tittle:%s\r\n" % newest)
          irc.send ("PRIVMSG #debug :URL: %s\r\n" % url)
          irc.send ("PRIVMSG #debug :MD5: %s\r\n" % id)
      while true:
          readRss()
          time.sleep(300)
  </code></pre>
  
  <p>if i add a while :true inside the while 1: with a time.sleep(300) the sleep command conflicts with the while 1: loop which i need to do something similar so i could check for new feeds every x minutes. what could i do?</p>