You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
argparse.ArgumentParser instances are not pickleable #144782
argparse.ArgumentParser instances are not pickleable, and being pickleable is necessary for multiprocessing to work. For example pytorch-lightning sends ArgumentParser objects between processes.
Even though the workaround solves the issue, there is no guarantee that changes in argparse make parsers unpickleable due to other reasons. For instance on Python 3.14.3 we are seeing the error:
_pickle.PicklingError: Can't pickle local object <function HelpFormatter._set_color.<locals>.<lambda>
It would be preferable that ArgumentParser is guaranteed to be pickleable here in cpython.
This issue doesn't suggest that all possible parsers should be pickleable. But it should be possible to build parsers with the intention of being pickleable.
A parser that is not pickleable because of a lambda in an add_argument is not a blocker. The problematic add_argument can be fixed in each project if needed. However, argparse.ArgumentParser itself not being pickleable, e.g. due to the new _set_color.<locals>.<lambda>, is a blocker. Multiprocessing in pytorch-lightning has been working for years without any issue thanks to the self.register('type', None, _identity) workaround. But now with Python 3.14.3 this is broken.
The Argparse parser instance doesn't strike me as something that should be pickleable. It's a very imperative messy stateful thing (e.g. colorization), I'm not sure the value proposition is really worth adding a new requirement and all that goes with that.
What is the expected behavior here?
Create argparse instance and pickle it to a file
export NO_COLOR to false, load picke file in a different process.
Also, if you're adding this feature, I believe there needs to be (at a minimum) a smoke test for the pickling of the subparser case.
Activity
mpkocher commentedon Feb 13, 2026
I think this might run into challenges depending on how people write the parser instance setup or "glue" around it.
Is this supposed to work?
Perhaps the argparse part might improved, but how people hook in to argparse, or put the glue around It will be fragile.
For example, I suspect patterns or styles like this will never work (and shouldn't be expected to be pickleable).
mauvilsa commentedon Feb 13, 2026
This issue doesn't suggest that all possible parsers should be pickleable. But it should be possible to build parsers with the intention of being pickleable.
A parser that is not pickleable because of a
lambdain anadd_argumentis not a blocker. The problematicadd_argumentcan be fixed in each project if needed. However,argparse.ArgumentParseritself not being pickleable, e.g. due to the new_set_color.<locals>.<lambda>, is a blocker. Multiprocessing in pytorch-lightning has been working for years without any issue thanks to theself.register('type', None, _identity)workaround. But now with Python 3.14.3 this is broken.gh-144782: Make sure that ArgumentParser instances are pickleable (#1…
pythongh-144782: Make sure that ArgumentParser instances are pickleab…
[3.14] gh-144782: Make sure that ArgumentParser instances are picklea…
mpkocher commentedon Feb 17, 2026
The Argparse parser instance doesn't strike me as something that should be pickleable. It's a very imperative messy stateful thing (e.g. colorization), I'm not sure the value proposition is really worth adding a new requirement and all that goes with that.
What is the expected behavior here?
Also, if you're adding this feature, I believe there needs to be (at a minimum) a smoke test for the pickling of the subparser case.
pythongh-144782: Make sure that ArgumentParser instances are pickleab…
pythongh-144782: Make sure that ArgumentParser instances are pickleab…