Ethan Welty <ethan.we...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue33111>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to