brianez21 0 Newbie Poster

Hi all,

I am writing a multi-threaded application in Python. On the client, there are 2 threads, a GUI thread that contains PyGTK functions, and a networking thread, which contains the listener loop below.

The problem is this - If the server sends the client a large amount of commands in a short period of time (say, 20 commands in 5 seconds), the whole program locks up and I have to kill it from the console.

def run(self):
	"""The main area of the thread that actaully does the listening on the network."""
	logfile.write("["+self.getName()+"] Starting instance of this thread...")
	while not self._stop.isSet():
		try:
			# The servers's loop; where its commands are processed by the client
			try:
				cmd, args = self.connection.get()
				execOk = True
			except socket.timeout:
				execOk = False
			except Exception, error:
				logfile.write("["+self.getName()+"] Couldn't get data, disconnecting:", str(error))
				break
			if execOk and not self._stop.isSet():
				try:
					self.executeCommand(cmd, args)
				except Exception, error:
					logfile.write("["+self.getName()+"] Disconnecting on server error:", str(error))
					break
		except Exception, error:
			logfile.write("["+self.getName()+"] Exception:", error)
			break
	self.stop()
	logfile.write("["+self.getName()+"] Done.")

Any advice on how to fix this would be helpful. This is my first multi-threaded Python project, so I would also appreciate any advice on proper handling of client network threads.

Thanks in advance,
Brian