I am actually using a pyopengl program to act as a socket server. At the same time the server receives commands from clients and interprets these commands and does corresponding drawing at the same time.
In case that the main thread got blocked when doing socket things I actually started a thread to do the socket server accept thing, and the updateserver socket method is called in the display loop.
class SocketServer(Thread):
def __init__ (self ):
Thread.__init__(self)
self.serversocket = socket(AF_INET, SOCK_STREAM);
self.serversocket.bind(("127.0.0.1", 7780));
self.status = -1;#not connected
self.clientsocket = None;
self.clientaddress = None;
self.clientbuffer = None;
self.serversocket.listen(5);
def run(self):
print 'thread running'
while( self.status == -1 ):
time.sleep(10);
(self.clientsocket, self.clientaddress) = self.serversocket.accept();
self.clientbuffer = self.clientsocket.makefile('r',0);
self.status = 0;
#Thread.kill();
#print 'SERVER LISTENNING FINISHED';
def getClientContent(self):
if ( not self.clientbuffer ): return "NONE CLIENT BUFFER";
return self.clientbuffer.readline();
ss = SocketServer();
def updateServerSocket():
global ss;
print ss.getClientContent();
- I don't know how to terminate the thread
- once the client written in another python file started to push data, the display loop got hangup as if it were dead