Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eurostat-fetcher
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dbnomics-fetchers
eurostat-fetcher
Commits
4b08c648
Commit
4b08c648
authored
7 years ago
by
Christophe Benz
Browse files
Options
Downloads
Patches
Plain Diff
Optimize lxml iterparse memory consumption
parent
d331439a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
eurostat_to_dbnomics.py
+8
-0
8 additions, 0 deletions
eurostat_to_dbnomics.py
with
8 additions
and
0 deletions
eurostat_to_dbnomics.py
+
8
−
0
View file @
4b08c648
...
...
@@ -240,6 +240,14 @@ def iter_git_objects_in_sdmx_file(sdmx_file_path, category_tree, validate_json):
yield
series_tree
dataset_tree
.
add
(
series_code
.
encode
(
'
utf-8
'
),
git_tree_filemode
,
series_tree
.
id
)
# From https://stackoverflow.com/questions/12160418/why-is-lxml-etree-iterparse-eating-up-all-my-memory
# It's safe to call clear() here because no descendants will be accessed
series_element
.
clear
()
# Also eliminate now-empty references from the root node to elem
for
ancestor
in
series_element
.
xpath
(
'
ancestor-or-self::*
'
):
while
ancestor
.
getprevious
()
is
not
None
:
del
ancestor
.
getparent
()[
0
]
# Write dataset.json
if
validate_json
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment