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

Add -Xcpu_count=process cmdline mode to redirect os.cpu_count as os.process_cpu_count #110649

Closed
corona10 opened this issue Oct 10, 2023 · 4 comments
Labels
type-feature A feature request or enhancement

Comments

@corona10
Copy link
Member

corona10 commented Oct 10, 2023

Since we add the os. process_cpu_count from #109649 and -Xcpu_count= command from #109595, we can easily redirect os.cpu_count to os. process_cpu_count as we discussed at #109595 (comment)

Linked PRs

@vstinner
Copy link
Member

What's the use case of this option? Would you mind to elaborate?

Why not modifying code to replace os.cpu_count() with os.process_cpu_count()?

I have doubts that this function is really needed.

cc @gpshead

@corona10
Copy link
Member Author

corona10 commented Oct 10, 2023

Why not modifying code to replace os.cpu_count() with os.process_cpu_count()?

Support -X cpu_count=process: os.cpu_count() becomes an alias to os.process_cpu_count(). So legacy applications using os.cpu_count() for use case (A) (decide how many worker processes should be run) and run in read-only containers with Python 3.13 can be run with -X cpu_count=process to use the correct number of CPUs. Obviously, -X cpu_count=number would remain available if the sysadmin has a good knowledge of its system or if Python returns the wrong number of CPUs (especially in groups).

Well, I consider the case that if people want to replace it without modifying source code(3rd party library) from os.cpu_count() and os.process_cpu_count() by default.

@vstinner
Copy link
Member

You can use export PYTHON_CPU_COUNT=$(python -c "import os; print(os.process_cpu_count())") which does the same, no?

@corona10
Copy link
Member Author

Same! Then let's close it

@corona10 corona10 added the type-feature A feature request or enhancement label Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants