gin-config icon indicating copy to clipboard operation
gin-config copied to clipboard

Modify exception object directly when reraising

Open danmou opened this issue 4 years ago • 0 comments

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.

danmou avatar Dec 07 '19 19:12 danmou