Skip to content Skip to sidebar Skip to footer

Can Pygame Events Be Handled In Select.select Input List?

The documentation for python's select.select says: Note that on Windows, it only works for sockets; on other operating systems, it also works for other file types (in particular

Solution 1:

You could use threads for this task. Is it necessary to process server messages and pygame events in series (not concurrently)? If so, you could do this:

classSocketListener(threading.Thread):
    def__init__(self, sock, queue):
         threading.Thread.__init__(self)
         self.daemon = True
         self.socket = sock
         self.queue = queue
    defrun(self):
         whileTrue:
             msg = self.socket.recv()
             self.queue.put(msg)
classPygameHandler(threading.Thread):
    def__init__(self, queue):
         threading.Thread.__init__(self)
         self.queue = queue
         self.daemon = Truedefrun(self):
         whileTrue:
             self.queue.put(pygame.event.wait())
queue = Queue.Queue()
PygameHandler(queue).start()
SocketListener(queue).start()
whileTrue:
    event = queue.get()
    """Process the event()"""

If not, you could process the events inside the run methods of the PygameHandler and SocketListener classes.

Post a Comment for "Can Pygame Events Be Handled In Select.select Input List?"