ecmwf / eccodes-python

Python interface to the ecCodes GRIB/BUFR decoder/encoder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File handle leak when using GribIndex

matthewlloyd opened this issue · comments

Steps to reproduce:

import eccodes
import os

print(os.getpid())
with eccodes.GribIndex('gribtest.grib2', ['level']) as index:
    print(index.size())

After running this code, the gribtest file handle is still open:

$ lsof -p 5262 | grep gribtest
ipython3 5262 user   12r   REG  202,1 341741882  427972 gribtest.grb2

This file handle leak isn't normally a problem, but when processing lots of files that get downloaded then deleted after processing, it consumes disk space quickly because the OS doesn't free the space until the file is actually closed by the process.

I'm using eccodes version 2.17.0. I'm not sure whether the issue is in the high-level Python API code (which looks correct), or in the underlying eccodes library.

Hi
There is an environment variable called ECCODES_FILE_POOL_MAX_OPENED_FILES.

The user can set this to an integer value e.g.
export ECCODES_FILE_POOL_MAX_OPENED_FILES=0

This will ensure no file is kept open.