Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make AsyncArray.nchunks_initialized async
This changes the API of AysncArray.nchunks_initialized to change it from a property to an async function. The motivation here comes from 1. general cleanliness (a property access calling async functions doing I/O feels a bit wrong) 2. Work on Array.info, where I hit a strange error, I think from jumping from a - sync Array.info_complete -> - async AsyncArray.info_complete -> - sync AsyncArray.nchunks_initialzed -> - sync collect_aiterator (async list_prefix) With this change, we'll be able to jump from sync to async just once at the boundary. ``` File "/Users/tom/gh/zarr-developers/zarr-python/src/zarr/core/array.py", line 3011, in info_complete return sync(self._async_array.info_complete()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/tom/gh/zarr-developers/zarr-python/src/zarr/core/sync.py", line 141, in sync raise return_result File "/Users/tom/gh/zarr-developers/zarr-python/src/zarr/core/sync.py", line 100, in _runner return await coro ^^^^^^^^^^ File "/Users/tom/gh/zarr-developers/zarr-python/src/zarr/core/array.py", line 1223, in info_complete "count_chunks_initialized": self.nchunks_initialized, # this should be async? ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/tom/gh/zarr-developers/zarr-python/src/zarr/core/array.py", line 844, in nchunks_initialized return nchunks_initialized(self) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/tom/gh/zarr-developers/zarr-python/src/zarr/core/array.py", line 3035, in nchunks_initialized return len(chunks_initialized(array)) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/tom/gh/zarr-developers/zarr-python/src/zarr/core/array.py", line 3061, in chunks_initialized collect_aiterator(array.store_path.store.list_prefix(prefix=array.store_path.path)) File "/Users/tom/gh/zarr-developers/zarr-python/src/zarr/core/sync.py", line 178, in collect_aiterator return sync(_collect_aiterator(data)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/tom/gh/zarr-developers/zarr-python/src/zarr/core/sync.py", line 128, in sync raise SyncError("Calling sync() from within a running loop") zarr.core.sync.SyncError: Calling sync() from within a running loop ```
- Loading branch information