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

Modify exception object directly when reraising #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danmou
Copy link

@danmou danmou commented Dec 7, 2019

In a multiprocessing scenario, you might want to send and exception through a pipe so it can be logged by the main process. This requires the exception to be pickleable, which is not the case when the exception is raised by a @gin.configurable-decorated function because utils.augment_exception_message_and_reraise creates a proxy class dynamically, which pickle can't access. That leads to an error similar this:

_pickle.PicklingError: Can't pickle <class 'ValueError'>: it's not the same object as builtins.ValueError

The simplest solution would be to modify the exception directly, as I have done in this PR. The resulting printed error will be exactly the same for the most common cases of exceptions with either no arguments or a single string argument. For exceptions with multiple arguments the message will be less readable but I can't think of a common use case for that anyway.

@sguada sguada requested a review from dhr December 7, 2019 22:11
@dhr dhr removed the cla: yes label Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants