1- try :
2- # Instantiating a Pool() attempts to import multiprocessing.synchronize,
3- # which fails if the underlying OS does not support semaphores.
4- # Here, we import ahead of time to decide which Pool implementation to use:
5- # one backed by Processes (the default), or one backed by Threads
6- import multiprocessing .synchronize # noqa: F401
7- except ImportError :
8- # Fallback to Threads on platforms that do not support semaphores
9- # https://github.com/pipxproject/pipx/issues/229
10- from multiprocessing .dummy import Pool
11- else :
12- from multiprocessing import Pool
13-
1+ from typing import Optional , Callable
142from pipx import constants
153from pipx .colors import bold
164from pipx .commands .common import get_package_summary
175from pipx .emojies import sleep
186from pipx .venv import VenvContainer
197
8+ Pool : Optional [Callable ]
9+ try :
10+ import multiprocessing .synchronize # noqa: F401
11+ from multiprocessing import Pool
12+ except ImportError :
13+ Pool = None
14+
2015
2116def list_packages (venv_container : VenvContainer ):
2217 dirs = list (sorted (venv_container .iter_venv_dirs ()))
@@ -29,6 +24,11 @@ def list_packages(venv_container: VenvContainer):
2924
3025 venv_container .verify_shared_libs ()
3126
32- with Pool () as p :
33- for package_summary in p .map (get_package_summary , dirs ):
27+ if Pool :
28+ with Pool () as p :
29+ for package_summary in p .map (get_package_summary , dirs ):
30+ print (package_summary )
31+ else :
32+ for d in dirs :
33+ package_summary = get_package_summary (d )
3434 print (package_summary )
0 commit comments