Skip to content

Compileall script: add option to use multiple cores #60308

Closed

Description

@dholth
mannequin
BPO 16104
Nosy @brettcannon, @gpshead, @merwok, @dholth, @PCManticore, @JimJJewett
Files
  • compileall_v1.patch
  • issue16104.patch: Remove trailing whitespaces
  • issue16104_1.patch
  • issue16104_2.patch: Minor doc fixes.
  • issue16104_3.patch
  • issue16104_4.patch
  • issue16104_5.patch
  • issue16104_6.patch
  • issue16104_7.patch: Skip a couple of tests if concurrent.futures is unavailable
  • issue16104_8.patch
  • issue16104_9.patch
  • issue16104_10.patch
  • issue16104_11.patch: Minor doc update
  • issue16104_12.patch
  • 16104.patch: Update the patch for the tip.
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/brettcannon'
    closed_at = <Date 2014-09-12.14:40:30.609>
    created_at = <Date 2012-10-01.20:46:54.073>
    labels = ['type-feature', 'library']
    title = 'Compileall script: add option to use multiple cores'
    updated_at = <Date 2020-02-27.08:02:38.705>
    user = 'https://github.com/dholth'

    bugs.python.org fields:

    activity = <Date 2020-02-27.08:02:38.705>
    actor = 'gregory.p.smith'
    assignee = 'brett.cannon'
    closed = True
    closed_date = <Date 2014-09-12.14:40:30.609>
    closer = 'brett.cannon'
    components = ['Library (Lib)']
    creation = <Date 2012-10-01.20:46:54.073>
    creator = 'dholth'
    dependencies = []
    files = ['33079', '34339', '34368', '34381', '34383', '34384', '34400', '34401', '34404', '35018', '35054', '35055', '35056', '35106', '36590']
    hgrepos = []
    issue_num = 16104
    keywords = ['patch']
    message_count = 28.0
    messages = ['171744', '171758', '205805', '213200', '213209', '213298', '213301', '213303', '213304', '213307', '213308', '213317', '213340', '213417', '213419', '213422', '214450', '217118', '217173', '217261', '217264', '217399', '217586', '226684', '226822', '226823', '226824', '362786']
    nosy_count = 7.0
    nosy_names = ['brett.cannon', 'gregory.p.smith', 'eric.araujo', 'dholth', 'Claudiu.Popa', 'python-dev', 'Jim.Jewett']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue16104'
    versions = ['Python 3.5']

    Activity

    1. dholth commented on Oct 1, 2012

      dholthmannequin
      MannequinAuthor

      compileall would benefit approximately linearly from additional CPU cores. There should be an option.

      The noisy output would have to change. Right now it prints "compiling" and then "done" synchronously with doing the actual work.

    2. brettcannon commented on Oct 1, 2012

      @brettcannon
      Member

      This should probably use concurrent.futures instead of multiprocessing directly, but yes it would be useful.

      Then again, the whole module should probably be rewritten to use importlib as well.

    3. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Oct 1, 2012
    4. self-assigned this
      on Mar 26, 2013
    5. removed their assignment
      on Apr 28, 2013
    6. PCManticore commented on Dec 10, 2013

      PCManticoremannequin
      Mannequin

      Hello!

      Here's a draft patch. It adds a new *processes* parameter to *compile_dir* and a new command line parameter as well.

    7. merwok commented on Mar 12, 2014

      @merwok
      Member

      Patch looks good. Some comments on Rietveld.

    8. PCManticore commented on Mar 12, 2014

      PCManticoremannequin
      Mannequin

      Thank you for the review, Éric! Here's the updated patch.

    9. merwok commented on Mar 12, 2014

      @merwok
      Member

      FTR, py_compile and compileall use importlib in 3.4.

    10. merwok commented on Mar 12, 2014

      @merwok
      Member

      This looks ready to me.

      One thing: “make -j0” is the spelling for “run using all available cores”, whereas “compileall -j0” will use one process. I don’t know if this should be documented, changed or ignored.

    11. brettcannon commented on Mar 12, 2014

      @brettcannon
      Member

      I vote for changed so that -j0 uses all available cores as os.cpu_count() states.

    12. PCManticore commented on Mar 12, 2014

      PCManticoremannequin
      Mannequin

      I agree. I'll modify the patch.

    13. merwok commented on Mar 12, 2014

      @merwok
      Member

      + if args.processes <= 0:
      Is that correct? For make, I think I’ve always seen “-j0”, not negative values.

      Could you add a test for -j0? (i.e. check that “compileall -j0” calls the function with “processes=os.cpu_count()”)

    14. PCManticore commented on Mar 12, 2014

      PCManticoremannequin
      Mannequin

      regrtest does that, checking for j <=0.

    15. 6 remaining items

    16. changed the title [-]Use multiprocessing in compileall script[/-] [+]Compileall script: add option to use multiple cores[/+] on Apr 23, 2014
    17. PCManticore commented on Apr 24, 2014

      PCManticoremannequin
      Mannequin

      Added a new version of the patch which incorporates suggestions made by Jim. Thanks for the review!

    18. jimjjewett commented on Apr 25, 2014

      jimjjewettmannequin
      Mannequin

      ProcessPoolExecutor already defaults to using cpu_count if max_workers is None. Consistency with that might be useful too. (and a default of 1 to mean nothing in parallel is sensible...)

    19. PCManticore commented on Apr 27, 2014

      PCManticoremannequin
      Mannequin

      Added a new patch with improvements suggested by Jim. Thanks!

      I removed the handling of processes=1, because it can still be useful: having a background worker which processes the files received from _walk_dir. Also, it checks that compile_dir receives a positive *processes* value, otherwise it raises a ValueError. As a side note, I just found that ProcessPoolExecutor / ThreadPoolExecutor don't verify the value of processes, leading to certain types of errors (see bpo-21362 for more details).
      Jim, the default for processes is still None, meaning "do not use multiple process", because the purpose of ProcessPoolExecutor makes it easy for it to use processes=None=os.cpu_count(). Here we want the user to be explicit about wanting multiple processes or not.

    20. PCManticore commented on Apr 27, 2014

      PCManticoremannequin
      Mannequin

      Add new patch with fixes proposed by Berker Peksag. Thanks for the review. Hopefully, this is the last iteration of this patch.

    21. jimjjewett commented on Apr 28, 2014

      jimjjewettmannequin
      Mannequin

      Trying to put bounds on the disagreements. Does anyone disagree with any of the following:

      (1) compileall currently runs single-threaded in a single process.

      (2) This enhancement intends to allow parallelization by process.

      (3) Users MAY need to express whether they (require/forbid/are expressly apathetic concerning) paralellization.

      (3A) There is some doubt that this even needs to be user-controlled.

      (3B) If it is user-controlled, the patch proposes adding a "processes" parameter to do this.

      (3C) There have been suggestions of other names (notably "workers"), but *if* it is user-controlled, the idea of a new parameter is not controversial.

      (4) Users MAY need to control the degree of parallelization.

      (4A) If so, setting the value of the new parameter to a positive integer > 1 is an acceptable solution.

      (4B) There is not yet consensus on how to represent "Use multi-processing, with the default degree for this system.", "Do NOT use multiprocessing.", or "I don't care."

      (4C) Suggested values have included 1, 0, -1, any negative number, None, and specific strings. The precise mapping between some of these and the three cases of 4B is not agreed.

      (5) If multiprocessing is explicitly requested, what should happen when it is not available?

      (5A) Fall back to the current way, without multi-processing.

      (5B) Fall back to the current way, without multi-processing, but issue a Warning.

      (5C) Raise an Exception. (ValueError, ImportError, NotImplemented?)

      (6) Portions of the documentation unrelated to this should be fixed. But ideally, that would be done separately, and it will NOT be a pre-requisite to this patch.

      ---------------------------------------------------

      Another potential value set

      None (the default) ==> let the system parallelize as best it can -- as it does in multiprocessing. If the system picks "not in parallel at all", that is also OK, and no warning is raised.

      0 ==> Do not parallelize.

      positive integers ==> Use that many processes.

      negative ==> ValueError

      Would these uses of 0 and negative be too surprising for someone?

    22. PCManticore commented on Apr 30, 2014

      PCManticoremannequin
      Mannequin

      Updated patch according to the python-dev thread:

      • processes renamed to workers
      • workers defaults to 1
      • When workers is equal to 0, then os.cpu_count will be used
      • When workers > 1, multiple processes will be used
      • When workers == 1, run normally (no multiple processes)
      • Negative values raises a ValueError
      • Will raise NotImplementedError if multiprocessing can't be used
        (when workers equals to 0 or > 1)
    23. PCManticore commented on Sep 10, 2014

      PCManticoremannequin
      Mannequin

      If there is nothing left to do for this patch, can it be committed?

    24. self-assigned this
      on Sep 10, 2014
    25. python-dev commented on Sep 12, 2014

      python-devmannequin
      Mannequin

      New changeset 9efefcab817e by Brett Cannon in branch 'default':
      Issue bpo-16104: Allow compileall to do parallel bytecode compilation.
      http://hg.python.org/cpython/rev/9efefcab817e

    26. brettcannon commented on Sep 12, 2014

      @brettcannon
      Member

      Thanks for the patch, Claudiu!

    27. PCManticore commented on Sep 12, 2014

      PCManticoremannequin
      Mannequin

      Thank you for committing it. :-)

    28. gpshead commented on Feb 27, 2020

      @gpshead
      Member

      This caused a regression in behavior. compileall.compile_dir()'s ddir= parameter no longer does the right thing for any subdirectories.

      https://bugs.python.org/issue39769

    29. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions