Skip to content

Modifying an array in a MemoryStore with multiprocessing does not work #3126

Open
@dstansby

Description

@dstansby

Zarr version

3.0.8

Numcodecs version

0.16.1

Python Version

3.13.0

Operating System

macOS

Installation

uv

Description

I'm trying to modify data concurrently, making sure I'm only modifying one chunk at a time. This doesn't seem to work with multiprocessing though.

Steps to reproduce

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "zarr@git+https://github.com/zarr-developers/zarr-python.git@main",
# ]
# ///
#
# This script automatically imports the development branch of zarr to check for issues

import zarr
from multiprocessing import Pool


def set_to_zero(array, idx):
    array[idx] = 0


if __name__ == "__main__":
    array = zarr.ones(shape=(2,), chunks=(1,))
    print(array[:])
    # prints [1, 1]

    args = [(array, 0), (array, 1)]

    with Pool(1) as pool:
        pool.starmap(set_to_zero, args)

    print(array[:])
    # prints [1, 1]; should print [0, 0]

    for arg in args:
        set_to_zero(*arg)

    print(array[:])
    # prints [0, 0]

Additional output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features or improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions