Python Forum
Segmentation fault with large files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Segmentation fault with large files
#1
Hi,

Here I'm trying to remove double quotation character from all text files. I'm getting an error "Segmentation fault" while I reading more than 8gb files in folder '/data/DWH/29SEP/'. Any comments?

import os

def Main():
    path = '/data/DWH/29SEP/'
    files = []
    for r, d, f in os.walk(path):
                for file in f:
                        if '.TXT' in file:
                                files.append(os.path.join(r, file))
    for f in files:
        print(f)
        with open(f + 'e', 'w') as outfile:
            with open(f, 'r') as infile:
                temp = infile.read().replace("\"", "")
                outfile.write(temp)

if __name__ == "__main__":
    Main()
Reply
#2
infile.read() loads the whole content of infile at once in memory. Read the file by chunks instead.
Reply
#3
(Oct-01-2019, 07:17 AM)Gribouillis Wrote: infile.read() loads the whole content of infile at once in memory. Read the file by chunks instead.

Hi Gribouillis,

Have you sample code?

Regards
Kusal
Reply
#4
Kusal1 Wrote:Hi Gribouillis,

Have you sample code?
Yes
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  make: *** [Makefile:29: all] Segmentation fault Anldra12 2 1,884 May-01-2022, 06:17 PM
Last Post: Anldra12
  Segmentation fault (core dumped) hobbyist 1 10,507 Jun-07-2021, 12:56 PM
Last Post: supuflounder
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,850 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Iterating Large Files Robotguy 10 5,172 Jul-22-2020, 09:13 PM
Last Post: Gribouillis
  Handling Large XML Files (>10GB) in Python onlydibs 1 4,213 Dec-22-2019, 05:46 AM
Last Post: Clunk_Head
  OpenCV - Segmentation fault samtwilliams 6 7,291 Sep-18-2019, 12:01 AM
Last Post: Larz60+
  Compare two large CSV files for a match Python_Newbie9 3 5,802 Apr-22-2019, 08:49 PM
Last Post: ichabod801
  Multiple calls to Python interpreter embedded in C++ application yield segmentation f mmoelle1 0 2,834 Mar-21-2019, 08:54 PM
Last Post: mmoelle1
  Comparing values in large txt files StevenVF 2 2,755 Feb-28-2019, 09:07 AM
Last Post: StevenVF
  Download multiple large json files at once halcynthis 0 2,787 Feb-14-2019, 08:41 AM
Last Post: halcynthis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020