From d6b0c5d0f8622ba81ffec03f6f32b65f3231763e Mon Sep 17 00:00:00 2001 From: Espy Date: Wed, 26 Sep 2018 07:47:28 +0100 Subject: [PATCH] Added a fallback to using a ThreadPoolExecutor for devices with no hardware semaphore implementation. --- black.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/black.py b/black.py index 66fc2a7ba2e..1be6c811f33 100644 --- a/black.py +++ b/black.py @@ -1,6 +1,6 @@ import asyncio from asyncio.base_events import BaseEventLoop -from concurrent.futures import Executor, ProcessPoolExecutor +from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor from datetime import datetime from enum import Enum, Flag from functools import lru_cache, partial, wraps @@ -340,7 +340,13 @@ def main( ) else: loop = asyncio.get_event_loop() - executor = ProcessPoolExecutor(max_workers=os.cpu_count()) + + cpu_count = os.cpu_count() + try: + executor = ProcessPoolExecutor(max_workers=cpu_count) + except ImportError: + executor = ThreadPoolExecutor(max_workers=cpu_count) + try: loop.run_until_complete( schedule_formatting(