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

Autodetect number of jobs with --jobs auto #605

Closed
wants to merge 2 commits into from

Conversation

lgeiger
Copy link
Contributor

@lgeiger lgeiger commented Jun 20, 2020

This adds the possibility to autodetect the number of jobs based on the number of available CPU cores on the host system using pytype --jobs auto. This allows for a usage similar to pytest-xdist which can be useful when using pytype in scripts that might run on different systems.

@@ -9,6 +10,20 @@

_ARG_PREFIX = '--'

def _auto_detect_cpus():
try:
return len(os.sched_getaffinity(0))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return the number of CPUs the current process is restricted to on Linux.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with os.cpu_count()?

Copy link
Contributor Author

@lgeiger lgeiger Jun 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux len(os.sched_getaffinity(0)) returns the number of CPUs available to the current process, where as os.cpu_count() will return the total number of CPUs on the host system which might be more than the current process can use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

answering my question - it's the number of available cores (not clear whether this includes hyperthreading cores).
More details: https://stackoverflow.com/questions/1006289/how-to-find-out-the-number-of-cpus-using-python/14840102

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clear whether this includes hyperthreading cores

As far as I know this includes hyperthreading cores. On my dual-core macbook --jobs auto will result in 4 parallel jobs.

Copy link
Contributor

@rchen152 rchen152 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a few nits related to the Google style guide.

pytype/tools/analyze_project/parse_args.py Show resolved Hide resolved
pytype/tools/analyze_project/parse_args.py Outdated Show resolved Hide resolved
pytype/tools/analyze_project/parse_args.py Show resolved Hide resolved
@lgeiger
Copy link
Contributor Author

lgeiger commented Jun 22, 2020

Just a few nits related to the Google style guide.

Fixed in 4e48291

@lgeiger lgeiger requested a review from rchen152 June 22, 2020 22:28
@rchen152 rchen152 closed this in 274cb27 Jun 23, 2020
@lgeiger lgeiger deleted the autodetect-jobs branch June 23, 2020 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants