Sitelet https://github.com/python/cpython/issues/74696
Skip to content

shutil.make_archive should not need to chdir (alternatively: make shutil.make_archive thread-safe) #74696

Description

@AlexGaynor
BPO 30511
Nosy @tarekziade, @ambv, @serhiy-storchaka, @miss-islington, @michael-o, @FFY00, @akulakov
PRs
  • bpo-30511: Add note on thread safety to shutil.make_archive() #26933
  • [3.10] bpo-30511: Add note on thread safety to shutil.make_archive() (GH-26933) #27274
  • [3.9] bpo-30511: Add note on thread safety to shutil.make_archive() (GH-26933) #27275
  • [3.8] bpo-30511: Add note on thread safety to shutil.make_archive() (GH-26933) #27276
  • bpo-25625: add contextlib.chdir #28271
  • 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 = None
    closed_at = None
    created_at = <Date 2017-05-30.13:46:18.840>
    labels = ['3.7', 'library']
    title = 'shutil.make_archive should not need to chdir (alternatively: make shutil.make_archive thread-safe)'
    updated_at = <Date 2021-09-17.13:26:13.713>
    user = 'https://bugs.python.org/AlexGaynor'

    bugs.python.org fields:

    activity = <Date 2021-09-17.13:26:13.713>
    actor = 'FFY00'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2017-05-30.13:46:18.840>
    creator = 'Alex Gaynor'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30511
    keywords = ['patch']
    message_count = 10.0
    messages = ['294756', '294758', '294759', '294760', '297902', '389849', '396633', '397928', '397932', '397934', '397935']
    nosy_count = 9.0
    nosy_names = ['tarek', 'lukasz.langa', 'serhiy.storchaka', 'Alex Gaynor', 'Joey Harrington', 'miss-islington', 'michael-o', 'FFY00', 'andrei.avk']
    pr_nums = ['26933', '27274', '27275', '27276', '28271']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue30511'
    versions = ['Python 2.7', 'Python 3.7']

    Activity

    1. AlexGaynor commented on May 30, 2017

      AlexGaynormannequin
      MannequinAuthor

      Currently shutil.make_archive uses os.chdir, however there's no need for that. Everything that's done could be equally accomplished with path manipulation:

      https://github.com/python/cpython/blob/master/Lib/shutil.py#L773-L779

      We should switch to using path manipulation in order to make shutil.make_archive thread safe.

      (Flag: This is probably a good bug for someone with Python skills interested in contributing to CPython!)

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on May 30, 2017
    3. serhiy-storchaka commented on May 30, 2017

      @serhiy-storchaka
      Member

      Unfortunately this is not possible. The signature of functions registered with register_archive_format() doesn't support this.

    4. AlexGaynor commented on May 30, 2017

      AlexGaynormannequin
      MannequinAuthor

      None of those functions are a public API, so changing them shouldn't be a problem IMO.

    5. AlexGaynor commented on May 30, 2017

      AlexGaynormannequin
      MannequinAuthor

      Ugh, except via |register_archive_format|. |register_archive_format| could wrap callables passed to it to maintain the current behavior.

    6. JoeyHarrington commented on Jul 7, 2017

      JoeyHarringtonmannequin
      Mannequin

      It would be nice if there was at least a warning in the docs that make_archive is not thread-safe, and that if you have two threads creating archives that it's extremely likely you'll get erroneous results since the race condition lasts for the entire duration of the archive creation.

    7. michael-o commented on Mar 30, 2021

      michael-omannequin
      Mannequin

      Just wasted two hours for this. Can someone really update the documentation of it if this is not going to change.

    8. akulakov commented on Jun 28, 2021

      @akulakov
      Contributor

      PR is added here:
      #26933

    9. ambv commented on Jul 21, 2021

      @ambv
      Contributor

      New changeset 64f54b7 by andrei kulakov in branch 'main':
      bpo-30511: Add note on thread safety to shutil.make_archive() (bpo-26933)
      64f54b7

    10. ambv commented on Jul 21, 2021

      @ambv
      Contributor

      New changeset d17449f by Miss Islington (bot) in branch '3.10':
      bpo-30511: Add note on thread safety to shutil.make_archive() (GH-26933) (GH-27274)
      d17449f

    11. ambv commented on Jul 21, 2021

      @ambv
      Contributor

      New changeset c8e35ab by Miss Islington (bot) in branch '3.9':
      bpo-30511: Add note on thread safety to shutil.make_archive() (GH-26933) (GH-27275)
      c8e35ab

    12. ambv commented on Jul 21, 2021

      @ambv
      Contributor

      New changeset 54d3871 by Miss Islington (bot) in branch '3.8':
      bpo-30511: Add note on thread safety to shutil.make_archive() (GH-26933) (bpo-27276)
      54d3871

    13. transferred this issue fromon Apr 10, 2022
    14. 14 remaining items

    15. added 2 commits that reference this issue on Jun 22, 2022
    16. ambv commented on Jun 22, 2022

      @ambv
      Contributor

      @gpshead I'm +1 to deprecate register_archive_format() in 3.12 and remove in 𝛑-Py. Can we use this issue for that or should I open a new one?

    17. serhiy-storchaka commented on Jun 22, 2022

      @serhiy-storchaka
      Member

      I was going to extend register_archive_format() by adding support of custom unpackers which support root_dir.

      It can be implemented either by adding a boolean parameter supports_root_dir in register_archive_format(), or checking the supports_root_dir attribute of the unpacker function.

    18. ambv commented on Jun 22, 2022

      @ambv
      Contributor

      Sure, Serhiy. Greg's point is that this functionality looks unused so it's probably an unnecessary support burden.

    19. serhiy-storchaka commented on Jun 22, 2022

      @serhiy-storchaka
      Member

      py7zr provides helpers to be registered in shutil. Other archiver modules can provide such helpers too or even register them by default. Removing register_archive_format() and register_unpack_format() will make other archive formats second-class citizens.

    20. added a commit that references this issue on Jun 25, 2022
    21. serhiy-storchaka commented on Jun 25, 2022

      @serhiy-storchaka
      Member

      I have implemented the second option in #94251. It seems better because does not need a collaboration between the author and users of the custom archiver.

    22. added a commit that references this issue on Oct 5, 2022
    23. added a commit that references this issue on Oct 6, 2022
    24. added a commit that references this issue on Oct 11, 2022
    25. Repository owner moved this from Todo to Done in Threading issues 🧵on Oct 27, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errortype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions