-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: self._hds cannot be converted to a Python object for pickling #3
Comments
Rasterio datasets can't be pickled and can't be shared between processes or threads. The work around is to distribute dataset identifiers (paths or URIs) and then open them in new threads. See rasterio/rasterio#1731. |
3 tasks
@sgillies thanks for your input on this issue: corteva/rioxarray#210 |
Intriguingly, the following code works. def default_profile():
return {
"count": 1,
"driver": "GTiff",
"dtype": "float32",
"nodata": -999999.0,
"width": 100,
"height": 100,
"transform": rasterio.Affine(1.0, 0.0, 0.0, 0.0, 1.0, 0.0),
"tiled": True,
"interleave": "band",
"compress": "lzw",
"blockxsize": 256,
"blockysize": 256,
}
def read_dataset(dataset, window):
dataset.read(window=window)
def write_dataset(dataset, pixels, window):
dataset.write(pixels, window=window)
if __name__ == "__main__":
mp.set_start_method("fork")
window = rasterio.windows.Window(col_off=0, row_off=0, width=20, height=20)
pixels = np.ones((1, 20, 20))
default_profile = default_profile()
with rasterio.open(Path("test_write.tiff"), mode="w", **default_profile) as dataset_write:
with rasterio.open(Path("test_read.tiff"), mode="r") as dataset_read:
p1 = mp.Process(target=read_dataset, args=(dataset_read, window))
p2 = mp.Process(target=write_dataset, args=(dataset_write, pixels, window))
p1.start()
p2.start()
p1.join()
p2.join() The output: Read dataset successfully.
Write dataset successfully. Am I missing something here? @sgillies |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems that rasterio's _hds object is no more serializable
The text was updated successfully, but these errors were encountered: