On Wed, 17 Jan 2018 20:53:42 -0500 Yury Selivanov <yselivanov.ml@gmail.com> wrote:
Proposed by Antoine Pitrou, this could enable transparent cross-process use of ``Context`` objects, so the `Offloading execution to other threads`_ example would work with a ``ProcessPoolExecutor`` too.
Enabling this is problematic because of the following reasons:
1. ``ContextVar`` objects do not have ``__module__`` and ``__qualname__`` attributes, making straightforward pickling of ``Context`` objects impossible. This is solvable by modifying the API to either auto detect the module where a context variable is defined, or by adding a new keyword-only "module" parameter to ``ContextVar`` constructor.
2. Not all context variables refer to picklable objects. Making a ``ContextVar`` picklable must be an opt-in.
This is a red herring. If a value isn't picklable, pickle will simply raise as it does in other contexts. You should't need to opt in for anything here. Regards Antoine.