Skip to content

Commit 48a2a8d

Browse files
author
bmartinn
committed
Update src/pip/_internal/req/__init__.py
Refactor Co-authored-by: Nguyễn Gia Phong
1 parent 2e39f53 commit 48a2a8d

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

src/pip/_internal/req/__init__.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,23 @@ def __safe_pool_map(
103103

104104
# first let's try to install in parallel,
105105
# if we fail we do it by order.
106-
pool = None
107-
results = None
108106
try:
107+
# Pool context would have been nice, but not supported on Python 2.7
108+
# Once officially dropped, switch to context to avoid close/join calls
109109
pool = Pool()
110-
pool_result = pool.map_async(func, iterable)
111-
# python 2.7 timeout=None will not catch KeyboardInterrupt
112-
results = pool_result.get(timeout=999999)
113-
except (KeyboardInterrupt, SystemExit):
114-
if pool:
115-
pool.terminate()
116-
raise
117-
except BaseException:
118-
# This should only happen if the pool failed to initialize
119-
# we fail silently and try serial installation
120-
if pool:
110+
except ImportError:
111+
return [func(i) for i in iterable]
112+
else:
113+
try:
114+
# python 2.7 timeout=None will not catch KeyboardInterrupt
115+
results = pool.map_async(func, iterable).get(timeout=999999)
116+
except (KeyboardInterrupt, SystemExit):
121117
pool.terminate()
122-
pool = None
123-
# close pool if it was active
124-
if pool:
125-
pool.close()
126-
pool.join()
127-
128-
return results
118+
raise
119+
else:
120+
pool.close()
121+
pool.join()
122+
return results
129123

130124

131125
def __single_install(

0 commit comments

Comments
 (0)