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

Exceptions with mandatory arguments are not reraised correctly #58

Closed
derHeinzer opened this issue Aug 15, 2022 · 2 comments · Fixed by #60
Closed

Exceptions with mandatory arguments are not reraised correctly #58

derHeinzer opened this issue Aug 15, 2022 · 2 comments · Fixed by #60
Assignees
Labels
bug Something isn't working

Comments

@derHeinzer
Copy link

derHeinzer commented Aug 15, 2022

If some exception with positional arguments is being raised by a subprocess, this exception is not being raised correctly. Most of the times it even causes deadlocks in my attempts to create minimum reproducable examples.

In case the exception takes exactly one argument, the exception message might be wrong. In case it takes more than one mandatory positional arguments the reraising will fail, because in following line the exception is assumed to take exactly one argument (the exception message)
https://github.com/Slimmer-AI/mpire/blob/0041051aaf4acf83e4c7e106a4f651d7ee6f3f26/mpire/pool.py#L752

Minimal examples:

from mpire import WorkerPool

class MyException1(Exception):
    def __init__(self, a, b):
        self.a = a
        self.b = b
        super().__init__(f"a={self.a}, b={self.b}")

class MyException2(Exception):
    def __init__(self, a):
        self.a = a
        super().__init__(f"a={self.a}")

def work1(x):
    raise MyException2(x)

def work2(x):
    raise MyException2(x, x)

with WorkerPool(n_jobs=5, use_dill=False) as pool:
    for res in pool.imap(work1, range(10)):
        if isinstance(res, Exception):
            raise res
        else:
            print(res)
@sybrenjansen
Copy link
Owner

I can confirm that this isn't working as expected. For some reason, I dismissed exceptions that have init arguments as an option. I will see if I can fix this.

@sybrenjansen sybrenjansen self-assigned this Aug 16, 2022
@sybrenjansen sybrenjansen added the bug Something isn't working label Aug 16, 2022
@sybrenjansen sybrenjansen mentioned this issue Aug 17, 2022
@sybrenjansen
Copy link
Owner

Fixed in v2.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants