-
-
Save akr4/3f367354a0026a1925ca91717a7a593b to your computer and use it in GitHub Desktop.
Python's XMLPullParser runs out of memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
import argparse | |
arg_parser = argparse.ArgumentParser() | |
arg_parser.add_argument('in_file') | |
args = arg_parser.parse_args() | |
def main(args): | |
with open(args.in_file) as f: | |
parser = ET.XMLPullParser(['start', 'end']) | |
for line in f: | |
parser.feed(line) | |
for event, elem in parser.read_events(): | |
pass | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using lxml or cElementTree and calling element.clear() solved the problem.