(original) (raw)

On Tue, Jan 16, 2018 at 4:37 PM, Antoine Pitrou <solipsis@pitrou.net> wrote:
On Tue, 16 Jan 2018 17:44:14 -0500
Yury Selivanov <yselivanov.ml@gmail.com> wrote:

\> Offloading execution to other threads
\> -------------------------------------
\>
\> It is possible to run code in a separate OS thread using a copy
\> of the current thread context::
\>
\> executor = ThreadPoolExecutor()
\> current\_context = contextvars.copy\_context()
\>
\> executor.submit(
\> lambda: current\_context.run(some\_function))

Does it also support offloading to a separate process (using
ProcessPoolExecutor in the example above)? This would require the
Context to support pickling.

I don't think that's a requirement. The transparency between the two different types of executor is mostly misleading anyway -- it's like the old RPC transparency problem, which was never solved IIRC. There are just too many things you need to be aware of before you can successfully offload something to a different process.

--
--Guido van Rossum (python.org/\~guido)