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
  How to optimize the speed of processing large JSON files in Python without using too sophia2005 3 964 Aug-02-2025, 03:25 PM
Last Post: snippsat
  how to download large files faster? kucingkembar 3 2,354 Feb-20-2025, 06:57 PM
Last Post: snippsat
  [pyparsing] How to make my simple parser fault tolerant medihack 0 1,397 May-14-2024, 04:52 PM
Last Post: medihack
  make: *** [Makefile:29: all] Segmentation fault Anldra12 2 3,641 May-01-2022, 06:17 PM
Last Post: Anldra12
  Segmentation fault (core dumped) hobbyist 1 17,525 Jun-07-2021, 12:56 PM
Last Post: supuflounder
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 11,645 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Iterating Large Files Robotguy 10 9,895 Jul-22-2020, 09:13 PM
Last Post: Gribouillis
  Handling Large XML Files (>10GB) in Python onlydibs 1 6,174 Dec-22-2019, 05:46 AM
Last Post: Clunk_Head
  OpenCV - Segmentation fault samtwilliams 6 10,567 Sep-18-2019, 12:01 AM
Last Post: Larz60+
  Compare two large CSV files for a match Python_Newbie9 3 7,721 Apr-22-2019, 08:49 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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