From 7d26afee0be6c99c16f4efb14cde6bf86dd63824 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 14 Sep 2021 15:45:57 -0700 Subject: [PATCH] Limit download_dart_sdk task pool size on Windows (flutter/engine#28623) The multiprocessing package relies on the win32 `WaitForMultipleObjects` call, which supports waiting on a maximum of MAXIMUM_WAIT_OBJECTS (defined by Windows to be 64) handles, processes in this case. To avoid hitting this, we limit ourselves to 60 handles (since there are a couple extra processes launched for the queue reader and thread wakeup reader). When left unspecified, the multiprocessing module defaults this value to os.cpu_count(), so this error is triggered only on machines with > 60 cores. See: https://bugs.python.org/issue2690 Bug: https://github.com/flutter/flutter/issues/90085 --- engine/src/flutter/tools/download_dart_sdk.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/tools/download_dart_sdk.py b/engine/src/flutter/tools/download_dart_sdk.py index 1e98a393e7..d77d8ccdeb 100755 --- a/engine/src/flutter/tools/download_dart_sdk.py +++ b/engine/src/flutter/tools/download_dart_sdk.py @@ -247,8 +247,21 @@ def Main(): if architectures == None: return fail_loudly + # Work around a bug in Python. + # + # The multiprocessing package relies on the win32 WaitForMultipleObjects() + # call, which supports waiting on a maximum of MAXIMUM_WAIT_OBJECTS (defined + # by Windows to be 64) handles, processes in this case. To avoid hitting + # this, we limit ourselves to 60 handles (since there are a couple extra + # processes launched for the queue reader and thread wakeup reader). + # + # See: https://bugs.python.org/issue26903 + max_processes = os.cpu_count() + if sys.platform.startswith(('cygwin', 'win')) and max_processes > 60: + max_processes = 60 + # Download and extract variants in parallel - pool = multiprocessing.Pool() + pool = multiprocessing.Pool(processes=max_processes) tasks = [(channel, semantic_version, os_name, arch, verbose) for arch in architectures] async_results = [pool.apply_async(DownloadAndExtract, t) for t in tasks] success = True