I have a function that runs tick () for all players and objects on my game server. I do this by looping through the set every 0.1 seconds. I need it to be durable. A lot of time and math depends on this pause, the maximum possible up to 0.1 seconds. For this, I added this to the tick tag:
start_time = time.time() # loops and code and stuff for tick thread in here... time_lapsed = time.time() - start_time # get the time it took to run the above code if 0.1 - time_lapsed > 0: time.sleep(0.1 - time_lapsed) else: print "Server is overloaded!" # server lag is greater that .1, so don't sleep, and just eat it on this run. # the goal is to never see this.
My question is: is this the best way to do this? If the duration of my cycle is 0.01, then time_lapsed == 0.01 ... and then sleep should only be 0.09. I ask because it does not seem to work. The other day, I started to get an overloaded message on the server, and the server was definitely not overloaded. Any thoughts on a good way to dynamically control sleep? Maybe there is another way to run the code every tenth of a second without sleep?
python time mud
jtsmith1287
source share