Skip to content

Commit

Permalink
Handle ImportError from multiprocessing module (#1400)
Browse files Browse the repository at this point in the history
Termux's Python environment doesn't provide sem_open, but fails with a
nested `ImportError` on import attempts:

    ImportError: cannot import name 'SemLock' from '_multiprocessing'

This updates the existing handling for AWS Lambda to catch both
`OSError` and `ImportError`.
  • Loading branch information
Terrance committed May 9, 2020
1 parent f6393a2 commit 865f536
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,9 @@ def reformat_many(
worker_count = min(worker_count, 61)
try:
executor = ProcessPoolExecutor(max_workers=worker_count)
except OSError:
except (ImportError, OSError):
# we arrive here if the underlying system does not support multi-processing
# like in AWS Lambda, in which case we gracefully fallback to
# like in AWS Lambda or Termux, in which case we gracefully fallback to
# a ThreadPollExecutor with just a single worker (more workers would not do us
# any good due to the Global Interpreter Lock)
executor = ThreadPoolExecutor(max_workers=1)
Expand Down

0 comments on commit 865f536

Please sign in to comment.