summaryrefslogtreecommitdiff
path: root/ot/utils.py
diff options
context:
space:
mode:
authorRĂ©mi Flamary <remi.flamary@gmail.com>2019-09-10 09:05:13 +0200
committerGitHub <noreply@github.com>2019-09-10 09:05:13 +0200
commit5e70a77fbb2feec513f21c9ef65dcc535329ace6 (patch)
tree3e800126f1de59640b0b1a09f763391ec3dc5318 /ot/utils.py
parentf251b4d080a577c2cee890ca43d8ec3658332021 (diff)
parent29848c2ab362fc5ff466cb0e12409a1cca61644f (diff)
Merge pull request #91 from rflamary/v1.0
[MRG] Release 0.6
Diffstat (limited to 'ot/utils.py')
-rw-r--r--ot/utils.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/ot/utils.py b/ot/utils.py
index d4127e3..b71458b 100644
--- a/ot/utils.py
+++ b/ot/utils.py
@@ -210,23 +210,28 @@ def fun(f, q_in, q_out):
def parmap(f, X, nprocs=multiprocessing.cpu_count()):
- """ paralell map for multiprocessing """
- q_in = multiprocessing.Queue(1)
- q_out = multiprocessing.Queue()
+ """ paralell map for multiprocessing (only map on windows)"""
- proc = [multiprocessing.Process(target=fun, args=(f, q_in, q_out))
- for _ in range(nprocs)]
- for p in proc:
- p.daemon = True
- p.start()
+ if not sys.platform.endswith('win32'):
- sent = [q_in.put((i, x)) for i, x in enumerate(X)]
- [q_in.put((None, None)) for _ in range(nprocs)]
- res = [q_out.get() for _ in range(len(sent))]
+ q_in = multiprocessing.Queue(1)
+ q_out = multiprocessing.Queue()
- [p.join() for p in proc]
+ proc = [multiprocessing.Process(target=fun, args=(f, q_in, q_out))
+ for _ in range(nprocs)]
+ for p in proc:
+ p.daemon = True
+ p.start()
- return [x for i, x in sorted(res)]
+ sent = [q_in.put((i, x)) for i, x in enumerate(X)]
+ [q_in.put((None, None)) for _ in range(nprocs)]
+ res = [q_out.get() for _ in range(len(sent))]
+
+ [p.join() for p in proc]
+
+ return [x for i, x in sorted(res)]
+ else:
+ return list(map(f, X))
def check_params(**kwargs):