Skip to content

Commit 24f76da

Browse files
committed
(joe) switch from multiprocessing.pool to internal wrapper, thanks to @McSinyx and @uranusjr for the warning about the weird ways in which different pythons are broken
1 parent 58259e8 commit 24f76da

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/pip/_internal/resolution/resolvelib/resolver.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import functools
22
import logging
33
import os
4-
from multiprocessing.pool import ThreadPool
54
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, cast
65

76
from pip._vendor.packaging.utils import canonicalize_name
@@ -22,6 +21,7 @@
2221
)
2322
from pip._internal.utils.deprecation import deprecated
2423
from pip._internal.utils.filetypes import is_archive_file
24+
from pip._internal.utils.parallel import LACK_SEM_OPEN, map_multithread
2525

2626
from .base import Candidate, Requirement
2727
from .factory import Factory
@@ -90,15 +90,21 @@ def resolve(
9090
reporter,
9191
)
9292

93-
def _maybe_find_candidates(req: Requirement) -> None:
94-
ident = provider.identify(req)
95-
try:
96-
self.factory._finder.find_all_candidates(ident)
97-
except AttributeError:
98-
pass
99-
100-
with ThreadPool() as tp:
101-
for _ in tp.imap_unordered(_maybe_find_candidates, collected.requirements):
93+
if LACK_SEM_OPEN:
94+
# if a working threading implementation unavailable do nothing
95+
pass
96+
else:
97+
# otherwise greedily call/consume _finder.find_all_candidates in parallel
98+
# in order to populate the lru cache such that future calls don't block on
99+
# networking
100+
def _maybe_find_candidates(req: Requirement) -> None:
101+
ident = provider.identify(req)
102+
try:
103+
self.factory._finder.find_all_candidates(ident)
104+
except AttributeError:
105+
pass
106+
107+
for _ in map_multithread(_maybe_find_candidates, collected.requirements):
102108
pass
103109

104110
try:

0 commit comments

Comments
 (0)