I am creating a simple multiplayer puzzle game in which multiple players can join a lobby and compete with each other. the player that submits the answer first gets the highest point, the player that submits the answers second gets the second highest point and so on..

How do I maintain the order of request on the server side?

I assume i cannot use an event-based server as it would become impossible to process requests in order.

a simple multithreaded server would be an ideal choice in this case as the requests will be short-lived.

initially, I was thinking to create the server in python but since it has not so good support for "real threads" it would mean compromising on performance.

My two main questions are:

  1. how is this scenario generally handled?
  2. how is this scenario generally handle if the language of choice is python?

1 Answer 1


When you have one or more threads which access the game state, then you want to avoid that more than one thread does so at the same time. Otherwise you can run into very hard to reproduce bugs which occur when one thread tries to access a data structure while another thread is in the middle of changing it.

In order to avoid this, you can use a Lock.

When your networking thread wants to check on the state of the game to see if it is the first to answer the question, use lock.acquire(). When no other thread has the lock acquired at the moment, the execution will continue immediately. When there is another thread which acquired the lock, then execution will pause until that thread does a lock.release(). That means a lock allows you to define a section of code where only one thread is allowed at a time. All other threads need to wait until it's their turn.


def checkAnswer( answer )


    if questionAlreadyAnswered:
         print "you were too slow."
         if answer == correctAnswer:
              print "correct!"
              questionAlreadyAnswered = true
              print "wrong!"


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .