Skip to content

Commit

Permalink
Update src/pip/_internal/req/__init__.py
Browse files Browse the repository at this point in the history
Refactor

Co-authored-by: Nguyễn Gia Phong <[email protected]>
  • Loading branch information
bmartinn and McSinyx authored May 11, 2020
1 parent 2e39f53 commit 93093f9
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/pip/_internal/req/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,21 @@ def __safe_pool_map(

# first let's try to install in parallel,
# if we fail we do it by order.
pool = None
results = None
try:
pool = Pool()
pool_result = pool.map_async(func, iterable)
# python 2.7 timeout=None will not catch KeyboardInterrupt
results = pool_result.get(timeout=999999)
except (KeyboardInterrupt, SystemExit):
if pool:
pool.terminate()
raise
except BaseException:
# This should only happen if the pool failed to initialize
# we fail silently and try serial installation
if pool:
except ImportError:
return [func(i) for i in iterable]
else:
try:
# python 2.7 timeout=None will not catch KeyboardInterrupt
results = pool.map_async(func, iterable).get(timeout=999999)
except (KeyboardInterrupt, SystemExit):
pool.terminate()
pool = None
# close pool if it was active
if pool:
pool.close()
pool.join()

return results
raise
else:
pool.close()
pool.join()
return results


def __single_install(
Expand Down

0 comments on commit 93093f9

Please sign in to comment.