New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get a path pointing to io.BytesIO? #402
Comments
I'm not sure I understand your question? But see https://docs.pyfilesystem.org/en/latest/guide.html#working-with-files and https://docs.pyfilesystem.org/en/latest/reference/base.html#fs.base.FS.readbytes |
@lurch I am going to try to explain it again. My program have an array of I have a Python library that loads files using systempath. However, I don't have any file stored just a memory array of bytes. So, I looked for I library that creates a syspath pointing to that bytes array. I make it work with the following code snippet.
I looked also |
@WaterKnight1998 If you have an API that only accepts a path and not a file-like object then I'm afraid your only option is to copy your data to the OS filesystem. It may look a bit awkward, but it's generally not all that slow. The OS may never actually physically write the data to disk. |
Okey. How can I achieve that The previous code snippet is a good idea? |
It's a feature of operating systems. When you work with files, the OS will try to cache files in memory as much as possible. Your snippet will likely work fine, but it's probably doing a little more work than necessary. TempFS will create a directory, which you don't strictly need. If you want it to be as efficient as possible, look at the tempfile module in the standard library, specifically the NamedTemporaryFile function. |
@willmcgugan Maybe something along these lines would be a useful addition to the FAQ ? |
...and on Linux, you could write your data-file into a subdirectory of |
Thank you for the info @willmcgugan I have tried next code snippet:
However, ND2 throws an error of lim not found! I think that I am saving bad the info and end mark is missed |
Nice to know. Could you give a little more intuition? |
@WaterKnight1998 I think you will need to close the file first, but make sure you create the file with @lurch I think you will pretty much get the same effect with a file in tmp/ depending on how its mounted. And the OS can still decide to use physical storage if it can't fit it in memory. At least that's my understanding... re FAQ, yeah maybe. I think this is the first time it's been asked. Unless my memory fails me! |
I think you need to
|
This do the trick @lurch and @willmcgugan :
|
By string you mean io.StringIO? @willmcgugan |
You can get the data from the StringIO with |
@willmcgugan the example in the docs is as follows:
I tried to use io.BytesIO but didn't work |
I also asqued them some days ago and they said this to me:
|
A quick bit of searching and it looks like it uses a C-based SDK in which case you'll need to go with the tempfile approach rather than trying to pass the string-value directly. |
Thank you for all your help!! @lurch & @willmcgugan |
I think passing |
I tried that and program is working too. Thank you for leeting know that However, the main bottleneck of my rest API is the deep learning model! |
I guess this can be closed then? Good luck with your deep learning 🤞 |
Thank you again for all your help!! |
Hi again @lurch and @willmcgugan I am facing no space left on device errors in /dev/shm inside docker container. Tracing memory usage with The code that I was using was
|
Off the top of my head, the code you've got there looks okay. I guess you'll need to do BTW there's no need to |
Yes, I was just adding it for trying to remove from remory
I am calling it explicity and getting same issues.
|
Deletting a buffer made the trick lel |
@lurch didn't do the trick.I was not trying with an nd2 file.... |
https://linux.die.net/man/2/unlink has more low-level details (i.e. a file can still be using up disk-space, even if it's not visible to |
I have tried commenting the the nd2_reader and looks like it is causing the error. It is based in C++ library. what could i do? |
I tried with another library for erading that file and it worked... So, the problem was that library OMG |
You could submit a bug-report against that library, saying that it isn't closing file-handles properly? |
Done, thank you! |
I am finding lot of librarys that use the filename for opening the file. However, in my Flask app I would like to get a filename that points to IO.BytesIO without the need o using temporal files
The text was updated successfully, but these errors were encountered: