Skip to content

Patch to add tempfile.SpooledTemporaryFile (for #415692) #44424

Closed

Description

@djmitche
mannequin
BPO 1630118
Nosy @arigo
Files
  • SpooledTemporaryFile.patch
  • 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 = <Date 2007-03-19.18:53:41.000>
    created_at = <Date 2007-01-07.20:36:07.000>
    labels = ['library']
    title = 'Patch to add tempfile.SpooledTemporaryFile (for python/cpython#34316)'
    updated_at = <Date 2007-03-19.18:53:41.000>
    user = 'https://bugs.python.org/djmitche'

    bugs.python.org fields:

    activity = <Date 2007-03-19.18:53:41.000>
    actor = 'collinwinter'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2007-01-07.20:36:07.000>
    creator = 'djmitche'
    dependencies = []
    files = ['7702']
    hgrepos = []
    issue_num = 1630118
    keywords = ['patch']
    message_count = 9.0
    messages = ['51691', '51692', '51693', '51694', '51695', '51696', '51697', '51698', '51699']
    nosy_count = 3.0
    nosy_names = ['arigo', 'collinwinter', 'djmitche']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1630118'
    versions = ['Python 2.6']

    Activity

    1. djmitche commented on Jan 7, 2007

      djmitchemannequin
      MannequinAuthor

      Attached please find a patch that adds a SpooledTemporaryFile class to tempfile, along with the corresponding documentation (optimistically labeling the feature as added in Python 2.5) and some test cases.

    2. added
      stdlib
      on Jan 7, 2007
    3. added
      stdlib
      on Jan 7, 2007
    4. djmitche commented on Jan 7, 2007

      djmitchemannequin
      MannequinAuthor

      File Added: SpooledTemporaryFile.patch

    5. arigo commented on Jan 8, 2007

      arigomannequin
      Mannequin

      The __getattr__ magic makes the following kind of code fail with SpooledTemporaryFile:

        f = SpooledTemporaryFile(max_size=something)
        rd = f.read
        wr = f.write
        for x in y:
            ...use rd(size) and wr(data)...

      The problem is that the captured 'f.read' method is the one from the StringIO instance, even after the write() rolled the file over to disk. Given that capturing bound methods is a semi-official speed hack advertised in some respected places, we might have to be careful about it. About such matters I am biased towards first getting it right and then getting it fast...

      Also, Python 2.5 is already out, so this will probably be a 2.6 addition.

    6. djmitche commented on Jan 8, 2007

      djmitchemannequin
      MannequinAuthor

      I agree it would break in such a situation, but I'm not clear on which direction your bias leads you (specifically, which do we get right -- don't use bound methods, or don't use the __getattr__ magic?).

      I could fix this by defining "proxy" functions (and some properties) for the whole file interface, rather than just the methods that potentially trigger rollover. That would lose a little efficiency, but mostly only in reading (calling e.g., f.read() will always result in two function applications; in the current model, after the first call it runs at "native" speed). It would also lose forward compatibility if the file protocol changes, although I'm not sure how likely that is.

      Would you like me to do that?

    7. arigo commented on Jan 11, 2007

      arigomannequin
      Mannequin

      Reimplementing the whole file interface as a proxy functions might be the safest route, yes.

      I realized that the __getattr__() magic is also used to serve at least one special method, namely the __iter__() of the file objects. This only works with old-style classes. In the long-term future, when old-style classes disappear and these classes become new-style, this is likely to introduce a subtle bug.

    8. djmitche commented on Feb 3, 2007

      djmitchemannequin
      MannequinAuthor

      Sounds good -- here's a new version.
      File Added: SpooledTemporaryFile.patch

    9. collinwinter commented on Mar 9, 2007

      collinwintermannequin
      Mannequin

      Did you mean to leave SpooledTemporaryFile out of tempfile.py's __all__? Also, would it be possible for you to add some tests for the pathological cases you and Armin discussed related to bound .read() and .write() methods?

    10. djmitche commented on Mar 18, 2007

      djmitchemannequin
      MannequinAuthor

      Slightly updated version to add STF to __all__ and add a test that bound methods work correctly.
      File Added: SpooledTemporaryFile.patch

    11. collinwinter commented on Mar 19, 2007

      collinwintermannequin
      Mannequin

      Applied as r54439. Thanks for your patch!

    12. 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

    No one assigned

      Labels

      stdlib

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions