tonykolomeytsev / kekmech-clapi-raspberry

A simple library for controlling Arduino and STM32 Nucleo via Raspberry Pi using Serial.
MIT License
1 stars 1 forks source link

Get rid of locks in the TaskPool class's main_loop method #3

Open tonykolomeytsev opened 5 years ago

tonykolomeytsev commented 5 years ago

There is a blocking code in main_loop method:

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.

The task is get rid of Lock()