[issue33111] Merely importing tkinter breaks parallel code (multiprocessing, sharedmem)

Ethan Welty report at bugs.python.org
Tue Mar 27 10:53:47 EDT 2018


Ethan Welty <ethan.welty at gmail.com> added the comment:

@ronaldoussoren: The order of the imports made no difference. Even with the call at the top, I got endless errors with both 'spawn' and 'forkserver', with or without importing a graphics backend. Only 'fork' works, and only if a graphics package is not imported.

** HOWEVER **

Setting method='spawn' or 'forkserver' and force=True at top, or calling multiprocessing.set_start_method in __main__ does work (when run as scripts from command line). It's a shame to have to give up the convenience of 'fork', but this is a start.

```
import multiprocessing
multiprocessing.set_start_method("spawn", force=True)
import numpy as np
# import _tkinter

def parallel_matmul(x):
    R = np.random.randn(3, 3)
    return np.matmul(R, x)

if __name__ == '__main__':
    # multiprocessing.set_start_method("spawn", force=False)
    pool = multiprocessing.Pool(4)
    results = pool.map(parallel_matmul, [np.random.randn(3, 5000) for i in range(2)])
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33111>
_______________________________________


More information about the Python-bugs-list mailing list