You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shutil.make_archive should not need to chdir (alternatively: make shutil.make_archive thread-safe) #74696
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=Noneclosed_at=Nonecreated_at=<Date2017-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=<Date2021-09-17.13:26:13.713>user='https://bugs.python.org/AlexGaynor'
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:
Unfortunately this is not possible. The signature of functions registered with register_archive_format() doesn't support this.
AlexGaynor commented on May 30, 2017
AlexGaynormannequin
MannequinAuthor
More actions
None of those functions are a public API, so changing them shouldn't be a problem IMO.
AlexGaynor commented on May 30, 2017
AlexGaynormannequin
MannequinAuthor
More actions
Ugh, except via |register_archive_format|. |register_archive_format| could wrap callables passed to it to maintain the current behavior.
JoeyHarrington commented on Jul 7, 2017
JoeyHarringtonmannequin
Mannequin
More actions
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.
michael-o commented on Mar 30, 2021
michael-omannequin
Mannequin
More actions
Just wasted two hours for this. Can someone really update the documentation of it if this is not going to change.
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.
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.
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.
Activity
AlexGaynor commentedon May 30, 2017
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!)
serhiy-storchaka commentedon May 30, 2017
Unfortunately this is not possible. The signature of functions registered with register_archive_format() doesn't support this.
AlexGaynor commentedon May 30, 2017
None of those functions are a public API, so changing them shouldn't be a problem IMO.
AlexGaynor commentedon May 30, 2017
Ugh, except via |register_archive_format|. |register_archive_format| could wrap callables passed to it to maintain the current behavior.
JoeyHarrington commentedon Jul 7, 2017
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.
michael-o commentedon Mar 30, 2021
Just wasted two hours for this. Can someone really update the documentation of it if this is not going to change.
akulakov commentedon Jun 28, 2021
PR is added here:
#26933
ambv commentedon Jul 21, 2021
New changeset 64f54b7 by andrei kulakov in branch 'main':
bpo-30511: Add note on thread safety to shutil.make_archive() (bpo-26933)
64f54b7
ambv commentedon Jul 21, 2021
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
ambv commentedon Jul 21, 2021
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
ambv commentedon Jul 21, 2021
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
14 remaining items
gh-74696: Do not change the current working directory in shutil.make_…
gh-74696: Do not change the current working directory in shutil.make_…
ambv commentedon Jun 22, 2022
@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?serhiy-storchaka commentedon Jun 22, 2022
I was going to extend
register_archive_format()by adding support of custom unpackers which supportroot_dir.It can be implemented either by adding a boolean parameter
supports_root_dirinregister_archive_format(), or checking thesupports_root_dirattribute of the unpacker function.ambv commentedon Jun 22, 2022
Sure, Serhiy. Greg's point is that this functionality looks unused so it's probably an unnecessary support burden.
serhiy-storchaka commentedon Jun 22, 2022
py7zr provides helpers to be registered in
shutil. Other archiver modules can provide such helpers too or even register them by default. Removingregister_archive_format()andregister_unpack_format()will make other archive formats second-class citizens.pythongh-74696: Pass root_dir to custom archivers which support it
serhiy-storchaka commentedon Jun 25, 2022
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.
Revert 30935 defer bpo45162 to 312 (#94285)
gh-74696: Pass root_dir to custom archivers which support it (GH-94251)
Merge branch 'main' into dictwatch
pythongh-74696: Pass root_dir to custom archivers which support it (p…