Skip to content

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

Description

@corona10

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

Activity

  1. vstinner commented on Oct 10, 2023

    @vstinner
    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

  2. corona10 commented on Oct 10, 2023

    @corona10
    MemberAuthor

    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.

  3. vstinner commented on Oct 10, 2023

    @vstinner
    Member

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

  4. corona10 commented on Oct 11, 2023

    @corona10
    MemberAuthor

    Same! Then let's close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions