I am looking for a way to thread my irc bot, so that there are multiple threads lisening in the same channel and every time they recieve something it will pick an idle thread and have it proccess the data so the bot can go right back to lisening. Also if there are not any idle threads it will spawn new ones.

I have played around with lots of other ideas i just can't get any to work. here is the base code without any threading stuff, the while loop is what i want each thread to processe the data with

Code:
import socket, time




##Config area- Below is what you edit

#select what network you are wanting to connect to
_network = "lancast.hopto.org"

#port of the network - defualt is 6667
_port = 6667

#channel- the channel on the network you want to be in
_channel = "generalgurus"

#NickName- the nickname of the bot
_nick = "chanBot"

#RealName- what do you want the servers realname to be
_name = "pyIRCbot"

#GeneralMsg- a msg that is displayed every 5 mins
_msg = "Check out our site @ http://generalgurus.com"

#blow are timings and controls on the antie spam stuff

#within time - the max number of things within how much time?
_withinTime = 300

#maxAmount - the max amount of msgs that can be sent within the within time
_maxMsg = 100

#warnLevel - what number do you want to warn at
_warn = 80

##End of config, don't edit anything below unless you know what your doing

#lets compile the re's to some things


#connect to the network and enter the channel
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( _network, _port ) )
irc.recv ( 4096 )
irc.send ( 'NICK %s\r\n' % _nick )
irc.send ( 'USER %s pyIRCbot pyIRCbot :%s \r\n' % ( _nick, _name ) )
irc.send ( 'JOIN #%s\r\n' % _channel )
irc.send ( 'PRIVMSG #%s :chanBot is up\r\n' % _channel )
irc.send ( 'PRIVMSG #%s :%s\r\n' % (_channel, _msg))

#lets set up are timer
timeMsg = time.time() + 3000

#now lets start the dictionary
users = {}

while True:
	data = irc.recv ( 4096 )
	print data
	function = data.split( ' ' ) [1] 
	if data[ :4 ] == "PING":
			irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
	if function == "PRIVMSG":
		#lets now check to see if it is time to do anything
		userNick = data.split ( '!' ) [ 0 ].replace ( ':', '' )
		if users.has_key(userNick):
			#this is if it is in the dictionary
			
			#lets get the list for the user we are dealing with
			userInfo = users[userNick]
			
			minTime = time.time() - _withinTime
			if userInfo[0] < minTime:
				#the user is int he clear so we can just reset them
				users[userNick] = [time.time(), 1]
			else:
			#lets see how much the user is pushing it
				msgCount = userInfo[1] + 1
				
				if msgCount == _maxMsg:
					#lets kick the user
					irc.send( 'KICK #%s %s :You need to stop the spaming' % (_channel, userNick))
				elif msgCount == _warn:
					#lets send out a warning
					irc.send( 'PRIVMSG #%s :%s you need to cool it with your spaming, continue and you will be kicked\r\n' % (_channel, userNick))
				
		else:
			#lets add the user to the dictionary
			users[userNick] = [time.time(), 1]
	
	#these are things that need to happen even if it just a ping
	if timeMsg <= time.time():
		irc.send ( 'PRIVMSG #%s :%s\r\n' % (_channel, _msg))
		timeMsg = time.time() + 3000

I have worked with threads in the past, but mainly for servers. I can't get it to have multiple threads i just can't figure out how to keep a certain number of threads alive and spawn more if needed, then not have each thread proccess the same data.