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

Unprotected use of multiprocessing.cpu_count() #520

Closed
henryiii opened this issue Nov 12, 2020 · 4 comments
Closed

Unprotected use of multiprocessing.cpu_count() #520

henryiii opened this issue Nov 12, 2020 · 4 comments

Comments

@henryiii
Copy link
Member

henryiii commented Nov 12, 2020

njobs = self.parallel if self.parallel else multiprocessing.cpu_count()

This could throw and is currently unprotected. See https://docs.python.org/3.5/library/multiprocessing.html#multiprocessing.cpu_count . Instead, maybe use os.cpu_count(), new in 3.4+: https://docs.python.org/3.5/library/os.html#os.cpu_count which returns None instead if undeterminable.

Suggestion:

njobs = self.parallel or multiprocessing.cpu_count() or 1
@HDembinski
Copy link
Member

Thank you that is a good suggestion, will do.

@henryiii
Copy link
Member Author

Looks good! Have I mentioned I love Python 3? :)

@HDembinski
Copy link
Member

Yes, it is great, and now that we don't have to support 3.5 anymore, I can also use f-strings in libraries...

@henryiii
Copy link
Member Author

henryiii commented Nov 15, 2020

I am curious to see pyupgrade on iMinuit, see scikit-hep/pyhf#1164.

Good, 3.6+ is great. :)

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

No branches or pull requests

2 participants