GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-29659: Expose copyfileobj() `length` arg for public use by goodboy · Pull Request #328 · python/cpython

Conversation

@goodboy

@goodboy goodboy commented Feb 27, 2017 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Corresponds to issue bpo-29659

When copying large files the copy time can be sufficiently
shortened by increasing the memory buffer used in the copyfileobj()
routine. Expose the length argument from copyfileobj() upwards
for use throughout the module.

https://bugs.python.org/issue29659

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni

the-knights-who-say-ni commented Feb 27, 2017

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow these steps to rectify the issue:

  1. Sign the PSF contributor agreement. The "bugs.python.org username" requested by the form is the "Login name" field in "Your Details" at b.p.o
  2. Wait at least one US business day and then check the "Contributor form received entry under "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  3. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Feb 27, 2017
@Mariatta Mariatta changed the title Expose copyfileobj() length arg for public use bpo-29659: Expose copyfileobj() length arg for public use Feb 27, 2017
@goodboy

goodboy commented Feb 27, 2017 via email

Copy link
Copy Markdown
Author
Hello, I have completed the above steps :) Thanks! Tyler Goodlet
…
On Sun, Feb 26, 2017 at 8:19 PM, the-knights-who-say-ni < ***@***.***> wrote: Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement <https://www.python.org/psf/contrib/contrib-form/> (CLA). Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow these steps to rectify the issue: 1. Sign the PSF contributor agreement <https://www.python.org/psf/contrib/contrib-form/>. The " bugs.python.org username" requested by the form is the "Login name" field in "Your Details" at b.p.o <https://cloud.githubusercontent.com/assets/2680980/23276970/d14a380c-f9d1-11e6-883d-e13b6b211239.png> 2. *Wait at least one US business day* and then check the "Contributor form received entry under "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA) 3. Reply here saying you have completed the above steps Thanks again to your contribution and we look forward to looking at it! — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#328 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AARzZYMi41HaBN6XwUx3iPTjPSu_myyrks5rgiSogaJpZM4MMmcV> .
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Mariatta Mariatta removed the CLA not signed label Feb 27, 2017
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Feb 27, 2017
vstinner
vstinner requested changes Mar 2, 2017
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must update Doc/library/shutil.rst: document the new parameter, but also add a ".. versionchanged:: 3.7" section to document the change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/shutil.py Outdated

@vstinner vstinner Mar 2, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest:

if not length:
length = 16 * 1024

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Mar 2, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/shutil.py Outdated

@vstinner vstinner Mar 2, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should document the default size: 16 kB.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Mar 2, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/shutil.py Outdated

@vstinner vstinner Mar 2, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same: document default size.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner vstinner added the type-feature A feature request or enhancement label Mar 2, 2017
@goodboy
goodboy force-pushed the expose_shutil_membuf-29659 branch from 4feede0 to 39a9b83 Compare March 3, 2017 05:25
@goodboy

goodboy commented Mar 3, 2017

Copy link
Copy Markdown
Author

@Haypo I believe I've addressed everything!
If there's anything I'm missing please let me know :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner requested changes Mar 3, 2017
View reviewed changes
Comment thread Doc/library/shutil.rst Outdated

@vstinner vstinner Mar 3, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn'd say "expose ..." but just "Added length parameter", and versionadded is not the right place to document "default is ...", put it in the documentation body.

You didn't update copyfile() signature. Same remark for the 2 other functions.

Moreover, you should also document the length in the function document, not only in versionadded. The "documentation" can just ask to refer to copyfileobj().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Mar 3, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoot yeah not sure how I missed the signatures...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/shutil.py Outdated

@vstinner vstinner Mar 3, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please mention the unit, "size in bytes"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Mar 3, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Haypo to clarify, do you prefer:
'An in-memory buffer size can be set with length; the default size in bytes is 16*1024',
or
"An in-memory buffer size in bytes can be set with length; the default is 16 KB.
?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Mar 3, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"An in-memory buffer size in bytes can be set withlength; the default is 16 KB."

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vadmium vadmium Sep 15, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encourage you to use KiB, which other parts of the documentation already use. If you write 16 KB it could easily be interpreted as 16,000 B (lower-case k means 1000, as in km for kilometre).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@goodboy
goodboy force-pushed the expose_shutil_membuf-29659 branch from 39a9b83 to 158a71b Compare March 3, 2017 19:24
@goodboy

goodboy commented Mar 3, 2017

Copy link
Copy Markdown
Author

@Haypo hopefully 3rd times the charm ;)

If you'd like me to squash the history to one commit let me know!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

terryjreedy
terryjreedy requested changes Mar 3, 2017
View reviewed changes

@terryjreedy terryjreedy left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: leave API of copyfileobj should alone as 'length=16*1024' to document default. For other functions, say something like 'If length not passed, copyfileobj uses its default.' We might change it someday.

Required: new or revised tests that use the expanded api (and fail without patch).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@goodboy

goodboy commented Mar 4, 2017

Copy link
Copy Markdown
Author

@terryjreedy the only problem with that is that we'll need to have the if length checks in all consuming functions as opposed to only once in copyfileobj no? Maybe you have a better approach?

Yes I totally agree about the test. I guess it goes here?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Mar 4, 2017 via email

Copy link
Copy Markdown
Member
Yes I totally agree about the test. I guess it goes here?
<https://github.com/python/cpython/blob/master/Lib/test/test_shutil.py#L1900> Yes.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

berkerpeksag
berkerpeksag reviewed Mar 15, 2017
View reviewed changes
Comment thread Doc/library/shutil.rst Outdated

@berkerpeksag berkerpeksag Mar 15, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation should use three spaces here:

.. versionchanged:: 3.7
   Added the *length* parameter.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@berkerpeksag berkerpeksag Mar 15, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`length` -> *length*

(and please finish the sentence with a full stop.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Sep 14, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Tyler Goodlet
Expose copyfileobj() length arg for public use
7fb7091
When copying large files the copy time can be sufficiently
shortened by increasing the memory buffer used in the `copyfileobj()`
routine.  Expose the `length` argument from `copyfileobj()` upwards
for use throughout the module.
@goodboy
goodboy force-pushed the expose_shutil_membuf-29659 branch from 158a71b to bfeaee8 Compare September 15, 2017 03:40
vadmium
vadmium reviewed Nov 5, 2017
View reviewed changes
Comment thread Doc/library/shutil.rst Outdated

@vadmium vadmium Nov 5, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO “Note that” is redundant. In fact the whole first line could be dropped, and “Only the contents from the current file position . . .” could be put back in the first paragraph.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@terryjreedy terryjreedy Nov 5, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Nov 20, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
vstinner
vstinner reviewed Nov 6, 2017
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please address pending comments before I can approve the change ;-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/shutil.py Outdated

@vstinner vstinner Nov 6, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: KiB

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Nov 20, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/shutil.py Outdated

@vstinner vstinner Nov 6, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8: add spaces around operators, "16 * 1024"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Nov 20, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/shutil.py Outdated

@vstinner vstinner Nov 6, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this empty line.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Nov 20, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner

vstinner commented Nov 6, 2017

Copy link
Copy Markdown
Member

Note: I created PR #4293 to replace KB with KiB in the Python code base ;-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Tyler Goodlet
Document exposure of the copyfileobj length arg in shutil
24b2f57
@goodboy
goodboy force-pushed the expose_shutil_membuf-29659 branch from bfeaee8 to 0043566 Compare November 20, 2017 01:27
@goodboy

goodboy commented Nov 20, 2017

Copy link
Copy Markdown
Author

I think everything has been addressed except for @terryjreedy's:

Suggestion: leave API of copyfileobj should alone as 'length=16*1024' to document default. For other functions, say something like 'If length not passed, copyfileobj uses its default.' We might change it someday.

I don't know how to keep the default value in copyfileobj but also support it as a default argument in all client functions without length = 16 * 1024 if length is None else length in each case. Personally I think that's a bit uglier. I can also stick the default value in each client function to be length=16 * 1024 and always pass it through transparently if that is preferred; it just means changing the value in multiple places if it is changed in the future. I had originally opted for one change in one place if it was to be modified later.

Whatever you all think is best I'll do 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner reviewed Nov 20, 2017
View reviewed changes
Comment thread Lib/test/test_shutil.py Outdated

@vstinner vstinner Nov 20, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use a smaller file: write('x' * 100) and then length=20.

By the way, I suggest to use tempfile.NamedTemporaryFile rather than temporary files:

            with tempfile.NamedTemporaryFile() as src:
                with tempfile.NamedTemporaryFile() as dst:
                    write_file(src.name, b'x' * 100, binary=True)
                    fn(src.name, dst.name, length=20)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@goodboy goodboy Nov 20, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe thanks @vstinner! You did the work for me 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Tyler Goodlet
Add test to using new length kwarg
8daf7a8
@goodboy
goodboy force-pushed the expose_shutil_membuf-29659 branch from 0043566 to 8daf7a8 Compare November 20, 2017 21:51
AraHaan
AraHaan reviewed Nov 20, 2017
View reviewed changes
Comment thread Lib/shutil.py

def copyfileobj(fsrc, fdst, length=16*1024):
"""copy data from file-like object fsrc to file-like object fdst"""
def copyfileobj(fsrc, fdst, length=None):

@AraHaan AraHaan Nov 20, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def copyfileobj(fsrc, fdst, length=16*1024):

I personally prefer this way in my code to concentrate 2 lines worth of code into one.

    if not length:
        length = 16 * 1024

It looks a little nicer and not to mention saves lines of code that basically do the same thing.
And yes I am also guilty of doing it this way and then people started hating me for it and calling my a bad programmer for it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@goodboy

goodboy commented Nov 21, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

Just to clear this up since it seems my original reasoning isn't showing well and the drive-by comments are piling up.

Afaict there are 3 ways to deal with the default value of length:

  • stick length=16*1024 in all three function signatures for copyfileobj, copy, and copy2

    • this means any time the default needs to be changed it will be done in 3 places
    • this is the least amount of lines of code
  • keep it the way it is (i.e. copy and copy2 define length=None in their signatures and one function, copyfileobj, has the current if length is None: check)

    • one more line of code then the previous solution
    • have to change the length in one place in the future
    • length is an explicit default argument in copy and copy2
  • make copy and copy2 take **kwargs and pass them through to the internal call to copyfileobj

    • same lines of code as the first solution
    • doesn't explicitly document length in each of the the copy, copy2 signatures
    • one place to change the default value in the future

If one of these solutions is preferred over the others after acknowledging the trade-offs I'm fine to do it, but just simply saying length=16*1024 is less code doesn't deal with how to handle copy and copy2 and the extra (or less clear) code they may contain.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@goodboy

goodboy commented Nov 21, 2017

Copy link
Copy Markdown
Author

@vstinner looks like the appveyor build failed due to the with open(path, 'wb' if binary else 'w') as fp: line?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Nov 22, 2017

Copy link
Copy Markdown
Member

@vstinner looks like the appveyor build failed due to the with open(path, 'wb' if binary else 'w') as fp: line?

ERROR: test_copy_w_different_length (test.test_shutil.TestShutil)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\cpython\lib\test\test_shutil.py", line 1417, in test_copy_w_different_length
    write_file(src.name, b'x' * 100, binary=True)
  File "C:\projects\cpython\lib\test\test_shutil.py", line 60, in write_file
    with open(path, 'wb' if binary else 'w') as fp:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\tmpj1vhtx1b'

Sorry, I don't know why the test failed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AraHaan

AraHaan commented Nov 22, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Looks to me like an normal permission error as python seems to not have permissions to write to the temp folder? Maybe somehow have python write to somewhere that does not require administrator permissions? It would be nice if python had an nice function that you provide the path and it checks if you have permissions to write to there to avoid having to try / except permission errors. 🤔 That function would be the perfect thing to fix this test on Windows.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@goodboy

goodboy commented Dec 11, 2017

Copy link
Copy Markdown
Author

Ok so besides the outstanding:

  • missing news entry
  • failing test

Is there anything else in the patch that needs to be addressed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AraHaan

AraHaan commented Dec 11, 2017

Copy link
Copy Markdown
Contributor

I dont think so.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner requested changes Dec 13, 2017
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike length=-1 "feature".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/shutil.py
"""
if not length:
length = 16 * 1024
while 1:

@vstinner vstinner Dec 13, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that it's ok to use a loop if the length is negative. I suggest to have a special case for negative value calling read() (no parameter) only once.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/shutil.rst
The integer *length*, if given, is the buffer size; the default value
in bytes is 16 KiB. A negative *length* value means to copy the data without
looping over the source data in chunks; by default the data is read in
chunks to avoid uncontrolled memory consumption.

@vstinner vstinner Dec 13, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"A negative length value means to copy the data without looping over the source data in chunks"

I dislike this definition. In practice, negative means "unlimited" buffer size: the whole input file is loaded into memory.

I'm not sure that it's a good practice to try to load files of unknown size into memory.

I suggest to remove this feature which seems more like a side effect than a carefully designed API.

If you want to get fast copy, pass a very large length like 1 GB. But if Python starts to load 1 TB into memory, it's likely to crash the system... At least, to slow down the system, a lot.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot

bedevere-bot commented Dec 13, 2017

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added the awaiting changes label Dec 13, 2017
@methane methane closed this Feb 25, 2019
@vstinner

vstinner commented Feb 25, 2019

Copy link
Copy Markdown
Member

Fixed by https://bugs.python.org/issue33671

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

klange pushed a commit to toaruos/cpython that referenced this pull request Sep 15, 2021
@gvanrossum
Issue python#28649: fix second issue with _ForwardRef (python#328) (3…
409d64a
….6->3.7)
jaraco pushed a commit that referenced this pull request Dec 2, 2022
@dependabot-preview @Mariatta
Bump gidgethub from 4.0.0 to 4.1.0 (#328)
822c36f
Bumps [gidgethub](https://github.com/brettcannon/gidgethub) from 4.0.0 to 4.1.0.
- [Release notes](https://github.com/brettcannon/gidgethub/releases)
- [Changelog](https://github.com/brettcannon/gidgethub/blob/master/docs/changelog.rst)
- [Commits](https://github.com/brettcannon/gidgethub/commits/v4.1.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Mariatta <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@berkerpeksag berkerpeksag berkerpeksag left review comments
@vadmium vadmium vadmium left review comments
@terryjreedy terryjreedy terryjreedy requested changes
@vstinner vstinner vstinner requested changes
+1 more reviewer
@AraHaan AraHaan AraHaan left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting changes type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@goodboy @the-knights-who-say-ni @vstinner @AraHaan @bedevere-bot @berkerpeksag @vadmium @terryjreedy @methane @Mariatta
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.