question about threading

sinan . orome.the.valar at gmail.com
Wed Aug 17 05:54:49 EDT 2005


hi i have a program that listens socket connection and serial device.
in main program i am creating a socket then calling a class to listen
socket under while 1: ,
class soket(Thread):
	def __init__(self):
			Thread.__init__(self)
			self.host = '127.0.0.1'
			self.port = 4500
			self.data = ''
			try:
				self.s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
				self.s.bind((self.host,self.port))
				self.s.listen(1)
			except:
				print 'error creating a socket !?!'
	def run(self):
		Thread.__init__(self)
		self.conn, self.addr = self.s.accept()
		self.data +=  self.conn.recv(1024)
		if not self.data:
			pass
		else:
			return trim(self.data)
		self.conn.close()


in main after doing this , 


try:
		s = AboutSocket.soket()
		s.setDaemon(1)
		s.start()
	except:
		print 'Error occured while using Threaded Socket !?!'

after creating a socket i put bot soket and serial listeners in same while 1:

      while 1:
		skcgelen = s.run()
		print '\n\nreceived data from socket : ' + skcgelen.__str__()
		okunan = serial_readline(ser,'[ETX]')
		print '\n\nreceived data : ' + okunan.__str__()
#		ser.write('[ACK]')
#		database_relation(db,okunan)  

this works but when i send message to serial, the program waits for
socket to receive message, if i send a message to a socket it prints
both socket message and serial device message, how can i work them
separetly. i want to see the message from the serial if received
immediately and socket if socket receives immediately. i`ll put these
incoming message to the list dynamically.
note: serial device listener is not threaded.
thanks



More information about the Python-list mailing list