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

kazoo client hangs with multiprocess #628

Open
fopguy41 opened this issue Oct 26, 2020 · 1 comment
Open

kazoo client hangs with multiprocess #628

fopguy41 opened this issue Oct 26, 2020 · 1 comment

Comments

@fopguy41
Copy link

fopguy41 commented Oct 26, 2020

kazoo client hangs when I use it within multiprocess.

I'm thinking it's most likely because it's not safe for a child and parent process to share kazoo client.

If that's true, what is the safe way for share a kazoo client within the same process, but still prevent hanging when using multiprocess?

Snippet to Reproduce the Problem

The following code is fine when using single process

client = None
def get_shared_kazoo_client():
    """ returns shared kazoo client"""
    from kazoo.client import KazooClient
    global client
    if client is None:
        client = KazooClient(hosts=KAZOOCLIENT)
        client.start()
    return client

def semaphore_function():
    client = get_shared_kazoo_client()
    throttler = client.Semaphore(max_leases=4, path='/test/path')
    with throttler:
        logging.info("inside")

if __name__ == '__main__':
    semaphore_function()
    semaphore_function()

This is fine no matter how many times I call semaphore_function().

However, the following code would hang.

if __name__ == '__main__':
    semaphore_function()
    p = mp.Process(target=semaphore_function)
    p.start()
    p.join()

The child process starts, but is unable to ever past with throttler.

I believe this post is observing similar behavior.
#519

I would like to have a global shared kazoo client to prevent unnecessarily constructing new kazoo clients over and over again. But, it fails the moment I start multiprocessing.

Any comments would be much appreciated.

Specifications

  • Kazoo version: 2.6.1
  • Python version: 3.6
  • OS: centOS 7
@wlazjr
Copy link

wlazjr commented Feb 10, 2022

any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants