Skip to content

incompatibility with concurrent.futures  #62

Open
@nmaxwell

Description

@nmaxwell

using tblib.pickling_support.install() causes an exception when using concurrent.futures.ProcessPoolExecutor. Here is a minimal example:

from concurrent.futures import ProcessPoolExecutor

import tblib.pickling_support

tblib.pickling_support.install()


def foo(x):
    if x > 2:
        raise RuntimeError('bar')


if __name__ == "__main__":
    with ProcessPoolExecutor(max_workers=2) as executor:

        try:
            list(
                executor.map(foo, range(50))
            )
        except Exception as ex:
            print('exception: ', ex)

    print(' --- done --- ')

I get an exception when the atexit functions run, this is the output:

exception:  bar
 --- done --- 
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/home/nick/lego-root/lib/python3.7/concurrent/futures/process.py", line 102, in _python_exit
    thread_wakeup.wakeup()
  File "/home/nick/lego-root/lib/python3.7/concurrent/futures/process.py", line 90, in wakeup
    self._writer.send_bytes(b"")
  File "/home/nick/lego-root/lib/python3.7/multiprocessing/connection.py", line 183, in send_bytes
    self._check_closed()
  File "/home/nick/lego-root/lib/python3.7/multiprocessing/connection.py", line 136, in _check_closed
    raise OSError("handle is closed")
OSError: handle is closed

Process finished with exit code 0

commenting out tblib.pickling_support.install() solves the problem, I then get the expected output with no exceptions:

exception:  bar
 --- done --- 

Process finished with exit code 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions