Re: GameThread slow
Posted: Tue Jul 25, 2023 11:38 pm
Could you please leave me a downloadable version of your InfiniteThread changes? I would like to try it out.
I've now updated the run function to your improved one:
Thank you, the server is now playable, but everytime the ThreadPoker is being triggered, e.g. by adding a function call, the server lags (loses tickrate) for a very short duration, as if it would been executed in the main thread. (I have tested it while being on the server, and while moving, you instantly notice the lag)
You can replicate it yourself by using:
test.py
I've now updated the run function to your improved one:
Syntax: Select all
def run(self):
while self.connected:
while not self.queue.empty():
with ThreadPoker():
callback, args, kwargs = self.queue.get_nowait()
callback(*args, **kwargs)
time.sleep(0.1) # Reduce CPU Load
Thank you, the server is now playable, but everytime the ThreadPoker is being triggered, e.g. by adding a function call, the server lags (loses tickrate) for a very short duration, as if it would been executed in the main thread. (I have tested it while being on the server, and while moving, you instantly notice the lag)
You can replicate it yourself by using:
test.py
Syntax: Select all
import time
from listeners.tick import GameThread
def test_function():
time.sleep(1.0)
print("test function")
thread = GameThread(target=test_function)
thread.start()