import time from concurrent.futures import ProcessPoolExecutor class ExceptionWithoutState(Exception): pass class ExceptionWithState(Exception): def __init__(self, state: str): super().__init__() self.state = state def main(): """ Minimal reproduction example. This routine will display the following output: ``` A process in the process pool was terminated abruptly while the future was running or pending. ``` In the first case the stateless exception is properly pickled and propagated back to the parent process. In the second case, somehow, raising the exception with state cause a `BrokenProcessPool` exception instead. I read there was some fixes that were push regarding the multithreading module and pickling... Maybe its related? """ with ProcessPoolExecutor() as executor: future = executor.submit(work_1) while not future.done(): time.sleep(0.0) exception = future.exception() print(type(exception)) print(exception) future = executor.submit(work_2) while not future.done(): time.sleep(0.0) exception = future.exception() print(type(exception)) print(exception) def work_1(): raise ExceptionWithoutState() def work_2(): raise ExceptionWithState(state="Fails when has state.") if __name__ == "__main__": main()