Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f150931

Browse files
Explicitly note the problem with functions defined in __main__.
1 parent 05a03ad commit f150931

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Doc/library/concurrent.futures.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ objects can be executed and returned.
251251
like with :class:`ProcessPoolExecutor`. Likewise, functions (and
252252
arguments) passed to :meth:`~Executor.submit` are pickled.
253253

254+
.. note::
255+
functions defined in the ``__main__`` module cannot be pickled
256+
and thus cannot be used.
257+
254258
*shared* is an optional dict of objects shared by all interpreters
255259
in the pool. The items are added to each interpreter's ``__main__``
256260
module. Not all objects are shareable. Those that are include

Lib/concurrent/futures/interpreter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def resolve_task(fn, args, kwargs):
5353
# XXX Keep the compiled code object?
5454
compile(data, '<string>', 'exec')
5555
else:
56-
# XXX This does not work if fn comes from the __main__ module.
56+
# Functions defined in the __main__ module can't be pickled,
57+
# so they can't be used here (for now). We could possibly
58+
# borrow from multiprocessing to work around this.
5759
data = pickle.dumps((fn, args, kwargs))
5860
kind = 'function'
5961
return (data, kind)

0 commit comments

Comments
 (0)