out of memory when saving a large string data into a text file using open() function

Yuichiro

I tried to save a large string data into a text file using following code.

@api.route("/upload/{project_name}/files")
async def receive_files(req, resp, *, project_name):

    @api.background.task
    def save_files(uploaded_data, project_name):

        filename = uploaded_data['filename']
        filedata = uploaded_data['data']


        with open(f"data/{project_name}/{filename}", "w", encoding="utf-8", newline="") as f:
            f.write(str(data))
            print('successfully saved', filename)

    data = await req.media()
    save_files(data, project_name)
    resp.media = {'success': True}

When I send a large file like 600MB csv file to this function, this process failed due to out of memory. It works with files less than 300MB. Is there any way I can optimize this function?? Thank you in advance.

I am using python-responder and a laptop with 16GB RAM

Yuichiro

I forgot to pass the right media format, files for responder-python.

data = await req.media(format='files')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Out of memory exception when decrypt large file using Cipher

From Dev

Perl "out of memory" with large text file

From Dev

Saving large text file with sections to Core Data attributes

From Dev

Saving large text file with sections to Core Data attributes

From Dev

Saving data to a text file using arduino and processing

From Dev

Compress large file using SharpZipLib causing Out Of Memory Exception

From Dev

Process out of memory error using nodejs when nothing should be that large

From Dev

Out of memory exception when using xlsx module with large files

From Dev

Saving output of a function to a text file

From Dev

"\n" not adding new line when saving the string to text using PrintWriter

From Dev

saving a structure of a list with the data in a text file using Python

From Dev

Extracting data from a text file using grep and saving it in another directory

From Dev

Saving a data structure to a text file

From Dev

Large File - Adding Lines - Out Of Memory

From Dev

Writing Large File To Disk Out Of Memory Exception

From Dev

Out of memory when creating large number of relationships

From Dev

Rapidminer - Out of memory when working on large datasets

From Dev

Rapidminer - Out of memory when working on large datasets

From Dev

Load a large text file into a string

From Dev

How to keep SSHD open when out of memory

From Dev

"Out of memory" error when using TTask.Run for a large number of job running in parallel

From Dev

Download large files using large byte array causes "Out of memory"

From Dev

String Index Out Of Range When Reading Text File

From Dev

String Index Out Of Range When Reading Text File

From Dev

Using scanner to read string from text file and then print out

From Dev

Error when downloading a large file using data link in javascript

From Dev

Filter data out from text file using php

From Dev

When writing large data into .csv file, is it better to open and close file often?

From Dev

Saving string to text file in AS3

Related Related

  1. 1

    Out of memory exception when decrypt large file using Cipher

  2. 2

    Perl "out of memory" with large text file

  3. 3

    Saving large text file with sections to Core Data attributes

  4. 4

    Saving large text file with sections to Core Data attributes

  5. 5

    Saving data to a text file using arduino and processing

  6. 6

    Compress large file using SharpZipLib causing Out Of Memory Exception

  7. 7

    Process out of memory error using nodejs when nothing should be that large

  8. 8

    Out of memory exception when using xlsx module with large files

  9. 9

    Saving output of a function to a text file

  10. 10

    "\n" not adding new line when saving the string to text using PrintWriter

  11. 11

    saving a structure of a list with the data in a text file using Python

  12. 12

    Extracting data from a text file using grep and saving it in another directory

  13. 13

    Saving a data structure to a text file

  14. 14

    Large File - Adding Lines - Out Of Memory

  15. 15

    Writing Large File To Disk Out Of Memory Exception

  16. 16

    Out of memory when creating large number of relationships

  17. 17

    Rapidminer - Out of memory when working on large datasets

  18. 18

    Rapidminer - Out of memory when working on large datasets

  19. 19

    Load a large text file into a string

  20. 20

    How to keep SSHD open when out of memory

  21. 21

    "Out of memory" error when using TTask.Run for a large number of job running in parallel

  22. 22

    Download large files using large byte array causes "Out of memory"

  23. 23

    String Index Out Of Range When Reading Text File

  24. 24

    String Index Out Of Range When Reading Text File

  25. 25

    Using scanner to read string from text file and then print out

  26. 26

    Error when downloading a large file using data link in javascript

  27. 27

    Filter data out from text file using php

  28. 28

    When writing large data into .csv file, is it better to open and close file often?

  29. 29

    Saving string to text file in AS3

HotTag

Archive