Skip to content
New issue

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

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

Already on GitHub? # to your account

How to solve the race condition problem in Pool multiprocessing #357

Open
jeffrey82221 opened this issue Mar 1, 2022 · 0 comments
Open

Comments

@jeffrey82221
Copy link

Hi,

When I am getting and closing DB connection (psycopg2) in the processes of billiard Pool, I found that getting and closing of DB connection will fail. Is there any way that I can add some lock to the getting and closing methods such that the race condition problem can be avoid?

In multiprocessing, a Lock object is provided. I wonder if there are something similar in billiard.

from multiprocessing import Process, Lock

def f(l, i):
    l.acquire()
    try:
        print('hello world', i)
    finally:
        l.release()

if __name__ == '__main__':
    lock = Lock()

    for num in range(10):
        Process(target=f, args=(lock, num)).start()
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant