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

Billiard hangs when exception is thrown in a finally block #402

Open
cesar-cortez5 opened this issue Mar 8, 2024 · 0 comments
Open

Billiard hangs when exception is thrown in a finally block #402

cesar-cortez5 opened this issue Mar 8, 2024 · 0 comments

Comments

@cesar-cortez5
Copy link

cesar-cortez5 commented Mar 8, 2024

Hello,
Recently we have noticed some hangs occurring, with no error messages.

Environment:
billiard version: 4.2.0
Python 3.10.12.

Cases which don't cause hanging, and cause hanging:

In test_cases.py

import time


def no_hang(id):
    raise Exception

def no_hang_1(id):
    time.sleep(1)
    raise Exception

def no_hang_2(id):
    try:
        time.sleep(1)
        raise Exception
    except:
        raise

def no_hang_3(id):
    try:
        pass
    finally:
        raise Exception

def no_hang_4(id):
    try:
        try:
            time.sleep(1)
        finally:
            raise Exception
    except:
        pass
        
def hang(id):
    try:
        time.sleep(1)
    finally:
        raise Exception

def hang_2(id):
    try:
        try:
            time.sleep(1)
        finally:
            raise Exception
    except:
        raise

In call_test_cases.py

import billiard as mp

# uncomment this line to use multiprocessing. 
# No hangs occur, unlike with billiard 
#import multiprocessing as mp

import func_that_fails
    

if __name__ == "__main__":
    for f in [
        test_cases.no_hang,
        test_cases.no_hang_1,
        test_cases.no_hang_2,
        test_cases.no_hang_3,
        test_cases.no_hang_4,
        test_cases.hang,
        test_cases.hang_2]:
        print(f"testing {f.__name__}")
        try:
            spawned_thread = mp.get_context("spawn")
            with spawned_thread.Pool(2) as pool:
                pool.map(f, [[1], [2], [3], [4]])
        except:
            print("correctly caught exception from inside pool.map")
        print("")

When using the standard multiprocessing library, no hangs occur. In order to reproduce this hang make sure the length of the iterable passed to map is greater than the number of worker processes spawned with Pool

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

1 participant