Skip to content

fix: make GokartBuildError picklable - #702

Merged
kitagry merged 2 commits into
masterfrom
fix/picklable-gokart-build-error
Nov 25, 2026
Merged

kitagry merged 2 commits into
masterfrom
fix/picklable-gokart-build-error

Conversation

@kitagry

@kitagry kitagry commented Nov 23, 2026

Copy link
Copy Markdown
Member

Closes #701

What

GokartBuildError could not be pickled. Exception.__reduce__ rebuilds an exception as cls(*self.args), and self.args is only (message,), so unpickling failed with TypeError: ... missing 1 required positional argument: 'raised_exceptions'. A GokartBuildError raised in a ProcessPoolExecutor worker broke the pool (BrokenProcessPool). In a multiprocessing.Pool worker, the pool's result-handler thread died and get() without a timeout waited forever.

This PR adds GokartBuildError.__reduce__, which rebuilds the error with (message, raised_exceptions) and restores the instance __dict__ as the state.

Tests

  • test_pickle_round_trip_keeps_message_and_attributes: the message, args, raised_exceptions and an extra attribute survive pickle.loads(pickle.dumps(e)).
  • test_error_raised_in_child_process_reaches_parent: a GokartBuildError raised in a ProcessPoolExecutor worker (spawn) reaches the parent as a GokartBuildError.

Both fail on master and pass with this change.

Relation to #684

#684 also changes the GokartBuildError class body: it adds status= to __init__ and a line after self.raised_exceptions = .... I built this PR on master rather than on #684, for these reasons:

Not in this PR

  • If a task raises an exception that can't be pickled itself, pickling the GokartBuildError still fails, because raised_exceptions holds that exception. This is a separate design question: replacing such exceptions with a stand-in would lose their type.
  • I considered giving raised_exceptions a default value instead, which would make the built-in reduce work. I chose not to, because it changes the public signature and makes raised_exceptions look optional.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CdA6RRuAhGPHPwCmTEgJGv

Exception.__reduce__ rebuilds an exception as cls(*self.args), and
GokartBuildError only puts the message in args, so unpickling failed with
a TypeError on the required raised_exceptions. A GokartBuildError raised
in a multiprocessing / ProcessPoolExecutor worker then broke the pool
instead of reaching the parent.

Closes #701

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CdA6RRuAhGPHPwCmTEgJGv

@hirosassa hirosassa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. __reduce__ rebuilds with (message, raised_exceptions) and restores __dict__, so attributes such as status from #684 survive without further changes. Both tests cover the reported failure (round trip and a ProcessPoolExecutor worker).

Resolve the conflict with #684 in test/test_build.py by keeping both
sets of tests, and check that the status added by #684 survives the
pickle round trip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kitagry
kitagry merged commit ecc53b6 into master Nov 25, 2026
7 checks passed
@kitagry
kitagry deleted the fix/picklable-gokart-build-error branch November 25, 2026 12:01
kitagry added a commit that referenced this pull request Nov 25, 2026
Resolve the conflict with #702 in test/test_build.py by keeping both
sets of tests. With #702, a GokartBuildError raised in a task now
reaches the parent as is with workers > 1, with its raised_exceptions
and status; add a test for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GokartBuildError cannot be pickled, so it breaks multiprocessing / ProcessPoolExecutor workers that call gokart.build

2 participants