Skip to content

Empty Exception for each open_rasterio call #929

Open

Description

@djmallum

I searched and was unable to find anyone else reporting this issue.

Code Sample

Here is my minimum working example

import numpy as np
import xarray as xr
import rioxarray as rio

y = np.linspace(40, 45, 10)
x = np.linspace(-75, -70, 10)

da = xr.DataArray(
    np.full((10, 10), np.nan),
    dims=['y', 'x'],
    coords={'y': y, 'x': x}
)

da.rio.write_crs('EPSG:4326') \
   .rio.set_spatial_dims(x_dim='x', y_dim='y') \
   .rio.to_raster('geo_grid.tif')

for i in range(1,100):
    loaded = rio.open_rasterio('geo_grid.tif')

Problem description

So in this case, after any exceptions (in the above there are none) or errors, 100 copies of the following are printed:

Error in sys.excepthook:

Original exception was:

Exactly as is, no additional detail. Whitespace is consistent.

Expected Output

Nothing.

Environment Information

With personal information censored/removed:

% python -c "import rioxarray; rioxarray.show_versions()"
rioxarray (0.22.0) deps:
  rasterio: 1.5.0
    xarray: 2026.4.0
      GDAL: 3.12.1
      GEOS: 0.0.0
      PROJ: 9.7.1

Other python deps:
     scipy: None
    pyproj: 3.7.2

System:
    python: 3.13.5 [Clang 17.0.0 (clang-1700.0.13.3)]
   machine: macOS-26.5.1

Installation method

Installed with pip in a venv.

Activity

  1. VolodymyrLinuxovich commented on Sep 26, 2026

    @VolodymyrLinuxovich
    Contributor

    I reproduced this on macOS with rioxarray master, rasterio 1.5.1 and xarray 2026.7.0: one empty Error in sys.excepthook block for each open_rasterio() that is still open at exit.

    It comes from rasterio 1.5, not rioxarray. The same script is silent with rasterio 1.4.3, and it reproduces with only xarray and rasterio: a CachingFileManager(rasterio.open, ...) left open at exit, with no rioxarray involved. xarray's atexit hook deliberately removes CachingFileManager.__del__, so datasets left in xarray's file cache are finalized very late, and rasterio 1.5's new DatasetBase.__del__ then tries to close them. rasterio #3563 was closed as fixed by rasterio #3612, but that fix is in 1.5.1 and this path still fails, so I've reported it upstream with a minimal reproducer: rasterio/rasterio#3646.

    Until that's fixed, any of these avoids it:

    # close explicitly
    data = rioxarray.open_rasterio("geo_grid.tif")
    ...
    data.close()
    
    # or use a context manager
    with rioxarray.open_rasterio("geo_grid.tif") as data:
        ...

    open_rasterio(..., lock=False) also didn't show the messages in my tests, but closing the dataset is the more robust fix.

    Update: a fix is proposed in rasterio/rasterio#3647. With it, the original script above exits cleanly.

  2. jsta commented on Sep 28, 2026

    @jsta

    The above didn't work for me, and the linked PR was closed in rasterio for apparent AI policy violation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions