question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File-like objects are closed after uploading

See original GitHub issue

Source boto/boto3#929

This is because we wrap them with the InterruptReader which closes them on exit.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:34
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
leogzylcommented, Apr 12, 2019

I’m using the following workaround:

from io import BufferedReader

class NonCloseableBufferedReader(BufferedReader):
    def close(self):
        self.flush()

buffer = NonCloseableBufferedReader(myfile)
client.upload_fileobj(Fileobj=buffer, Bucket=bucket, Key=name)
buffer.detach()
assert not myfile.closed
8reactions
al-muammarcommented, Dec 30, 2019

3 years passed… Can it be either fixed or declared to be not a bug, so other libraries should build workarounds for it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What can I do with a closed file object? - python - Stack Overflow
One use is using the name to reopen the file: open(f.name).read(). I use the name attribute when changing a file content using a ......
Read more >
File Handling in Pillow - Pillow (PIL Fork) 9.3.0 documentation
If a filename or a path-like object is passed to Pillow, then the resulting file object opened by Pillow may also be closed...
Read more >
Uploading objects - Amazon Simple Storage Service
When you upload a file to Amazon S3, it is stored as an S3 object. Objects consist of the file data and metadata...
Read more >
Request Files - FastAPI
This is because uploaded files are sent as "form data". Import File ¶. Import File and UploadFile from fastapi :.
Read more >
Python File Operations - Read and Write to files with Python
We will also learn some useful operations such as copy file and delete ... When you open a file in Python, it's extremely...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found