Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to threads if no semaphore support #277

Merged
merged 1 commit into from
Nov 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/pipx/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import datetime
import hashlib
import logging
import multiprocessing
import shlex
import shutil
import subprocess
Expand All @@ -16,6 +15,19 @@
from shutil import which
from typing import List

try:
# Instantiating a Pool() attempts to import multiprocessing.synchronize,
# which fails if the underlying OS does not support semaphores.
# Here, we import ahead of time to decide which Pool implementation to use:
# one backed by Processes (the default), or one backed by Threads
import multiprocessing.synchronize # noqa: F401
except ImportError:
# Fallback to Threads on platforms that do not support semaphores
# https://github.com/pipxproject/pipx/issues/229
from multiprocessing.dummy import Pool
else:
from multiprocessing import Pool

import userpath # type: ignore
from pipx import constants
from pipx.colors import bold, red
Expand Down Expand Up @@ -574,7 +586,7 @@ def list_packages(venv_container: VenvContainer):

venv_container.verify_shared_libs()

with multiprocessing.Pool() as p:
with Pool() as p:
for package_summary in p.map(_get_package_summary, dirs):
print(package_summary)

Expand Down