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

Speed up pip list --outdated #7962

Merged
merged 18 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions news/7962.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`pip list --outdated` version fetching is multi-threaded
CrafterKolyan marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 12 additions & 2 deletions src/pip/_internal/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import json
import logging
from multiprocessing.pool import ThreadPool

from pip._vendor import six
from pip._vendor.requests.adapters import DEFAULT_POOLSIZE
from pip._vendor.six.moves import zip_longest

from pip._internal.cli import cmdoptions
Expand Down Expand Up @@ -183,9 +185,17 @@ def iter_packages_latest_infos(self, packages, options):
with self._build_session(options) as session:
finder = self._build_package_finder(options, session)

for dist in packages:
# Doing multithreading in Python 2 compatible way
executor = ThreadPool(DEFAULT_POOLSIZE)
all_candidates_list = executor.map(
finder.find_all_candidates,
[dist.key for dist in packages]
)
executor.close()
executor.join()

for dist, all_candidates in zip(packages, all_candidates_list):
typ = 'unknown'
all_candidates = finder.find_all_candidates(dist.key)
if not options.pre:
# Remove prereleases
all_candidates = [candidate for candidate in all_candidates
Expand Down
2 changes: 2 additions & 0 deletions src/pip/_internal/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def indent_log(num=2):
A context manager which will cause the log output to be indented for any
log messages emitted inside it.
"""
# For thread-safety
_log_state.indentation = get_indentation()
_log_state.indentation += num
try:
yield
Expand Down