Skip to content

Commit d47627f

Browse files
authored
Merge pull request #84805 from charles-zablit/charles-zablit/update-checkout/fix-python39-deadlock-issue
[update-checkout] force the use of verbose mode if -j is set to a high value
2 parents b648818 + 6433803 commit d47627f

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

utils/update_checkout/update_checkout/parallel_runner.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(
1515
fn: Callable,
1616
running_tasks: ListProxy,
1717
updated_repos: ValueProxy,
18-
lock: Lock
18+
lock: Lock,
1919
):
2020
self.fn = fn
2121
self.running_tasks = running_tasks
@@ -48,13 +48,7 @@ def __init__(
4848
):
4949
self._monitor_polling_period = 0.1
5050
if n_processes == 0:
51-
if sys.version_info.minor < 10:
52-
# On Python < 3.10, https://bugs.python.org/issue46391 causes
53-
# Pool.map and its variants to hang. Limiting the number of
54-
# processes fixes the issue.
55-
n_processes = int(cpu_count() * 1.25)
56-
else:
57-
n_processes = cpu_count() * 2
51+
n_processes = ParallelRunner._max_processes()
5852
self._terminal_width = shutil.get_terminal_size().columns
5953
self._n_processes = n_processes
6054
self._pool_args = pool_args
@@ -106,7 +100,7 @@ def _monitor(self):
106100
self._lock.release()
107101

108102
if current_line != last_output:
109-
truncated = (f"{self._output_prefix} [{updated_repos}/{self._nb_repos}] ({current_line})")
103+
truncated = f"{self._output_prefix} [{updated_repos}/{self._nb_repos}] ({current_line})"
110104
if len(truncated) > self._terminal_width:
111105
ellipsis_marker = " ..."
112106
truncated = (
@@ -147,3 +141,12 @@ def check_results(results, op) -> int:
147141
print(r.stderr.decode())
148142
return fail_count
149143

144+
@staticmethod
145+
def _max_processes() -> int:
146+
if sys.version_info.minor < 10:
147+
# On Python < 3.10, https://bugs.python.org/issue46391 causes
148+
# Pool.map and its variants to hang. Limiting the number of
149+
# processes fixes the issue.
150+
return int(cpu_count() * 1.25)
151+
else:
152+
return cpu_count() * 2

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,15 @@ def main():
801801
"sockets will exceed the size limit. Falling back to verbose mode."
802802
)
803803
args.verbose = True
804+
elif (
805+
sys.version_info.minor < 10
806+
and args.n_processes > ParallelRunner._max_processes()
807+
):
808+
print(
809+
"Falling back to verbose mode due to a Python 3.9 limitation. "
810+
f"Lower `-j` below {ParallelRunner._max_processes()} to use non verbose mode."
811+
)
812+
args._verbose = True
804813

805814
clone = args.clone
806815
clone_with_ssh = args.clone_with_ssh

0 commit comments

Comments
 (0)