I have gone through many Google App Engine tutorials, and I became quite familiar with how to do basic stuff like implementing a webapp2.RequestHandler
, and using ndb.Models
to manage your data.
Now, I kind of reached a wall with a few small concepts that were either missing from the resources I went over, or I simply missed them. So, here they are:
What happens to class variables?
As far as I understood, once I set my app to threadsafe, it can handle multiple requests concurrently, not to mention possibly on different machines. Does that mean I simply cannot use class variables (that can be changed at anytime)?
How to model an application wide logic?
It is very straight forward to write logic associated with requests. I don't have to worry about locking or any of that stuff, since a new RequestHandler is instantiated for each request. What about application-wide logic? Like, if I had a python module called "Game", and after importing it, I do somthing like:
Game.matchmaking_queue.append(player)
As far as I can tell, there is just one Game
instance, and it has an instance variable accessed from within the RequestHandler
logic. Will that be OK? Must I make the matchmaking_queue
backed on memcache and/or datastore in order for all requests to see it? Do I have to do any thread-saftey magic on Game
?