Skip to content

Commit

Permalink
pythongh-125864: Propagate pickle.loads() failures in `InterpreterP…
Browse files Browse the repository at this point in the history
…oolExecutor` (pythongh-125898)

Authored-by: Peter Bierma <[email protected]>
  • Loading branch information
ZeroIntensity authored Oct 24, 2024
1 parent 3c4a7fa commit 41bd9d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Lib/concurrent/futures/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def _call(cls, func, args, kwargs, resultsid):

@classmethod
def _call_pickled(cls, pickled, resultsid):
fn, args, kwargs = pickle.loads(pickled)
with cls._capture_exc(resultsid):
fn, args, kwargs = pickle.loads(pickled)
cls._call(fn, args, kwargs, resultsid)

def __init__(self, initdata, shared=None):
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_concurrent_futures/test_interpreter_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ def pipe(self):
return r, w


class PickleShenanigans:
"""Succeeds with pickle.dumps(), but fails with pickle.loads()"""
def __init__(self, value):
if value == 1:
raise RuntimeError("gotcha")

def __reduce__(self):
return (self.__class__, (1,))


class InterpreterPoolExecutorTest(
InterpretersMixin, ExecutorTest, BaseTestCase):

Expand Down Expand Up @@ -279,6 +289,14 @@ def test_idle_thread_reuse(self):
self.assertEqual(len(executor._threads), 1)
executor.shutdown(wait=True)

def test_pickle_errors_propagate(self):
# GH-125864: Pickle errors happen before the script tries to execute, so the
# queue used to wait infinitely.

fut = self.executor.submit(PickleShenanigans(0))
with self.assertRaisesRegex(RuntimeError, "gotcha"):
fut.result()


class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase):

Expand Down

0 comments on commit 41bd9d9

Please sign in to comment.