How to solve the race condition problem in Pool multiprocessing

Open
#357 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
postgresql, python

Research direction

The issue names billiard Pool, multiprocessing.Process/Lock, and psycopg2, but no repository file or failing test. Start by reproducing the reported connection get/close failure and compare billiard's synchronization support with multiprocessing.Lock. Done is not defined beyond finding whether a safe locking approach exists.

Written by the indexing model from the issue text.

Description

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()
Dominant language
Python
Stars
436
Forks
273
Avg merge
4d 19h
Merged PRs (30d)
5

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from celery/billiard

All issues in celery/billiard

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.