def main_loop(self):
while True:
self.task_lock.acquire() # <-------------------------------HERE
# принимаем все входящие сообщения
self.process_input()
if len(self.tasks):
self.process_output()
else:
time.sleep(0) # аналог thread.yield() в других языках
self.task_lock.release() # <--------------------------------- AND HERE
This is because you need to be able to safely add to the list of tasks while running main_loop. I am sure that there is a more elegant solution, I just do not know about it.
There is a blocking code in main_loop method:
This is because you need to be able to safely add to the list of tasks while running
main_loop
. I am sure that there is a more elegant solution, I just do not know about it.The task is get rid of
Lock()