Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tonykolomeytsev opened this issue Jun 14, 2019 · 0 comments
Open
Labels
perfomance This code may work faster

Comments

@tonykolomeytsev
Copy link
Owner

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()

@tonykolomeytsev tonykolomeytsev added the perfomance This code may work faster label Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perfomance This code may work faster
Projects
None yet
Development

No branches or pull requests

1 participant