Commit a82d047
Make AsyncArray.nchunks_initialized async (zarr-developers#2449)
* 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
```
* fixup
---------
Co-authored-by: Davis Bennett <[email protected]>1 parent 0f56ac2 commit a82d047
2 files changed
+54
-51
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
829 | 829 | | |
830 | 830 | | |
831 | 831 | | |
832 | | - | |
833 | | - | |
| 832 | + | |
834 | 833 | | |
835 | | - | |
| 834 | + | |
| 835 | + | |
836 | 836 | | |
837 | 837 | | |
838 | 838 | | |
839 | | - | |
840 | | - | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
841 | 855 | | |
842 | | - | |
| 856 | + | |
843 | 857 | | |
844 | 858 | | |
845 | 859 | | |
| |||
1492 | 1506 | | |
1493 | 1507 | | |
1494 | 1508 | | |
1495 | | - | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
1496 | 1530 | | |
1497 | | - | |
| 1531 | + | |
1498 | 1532 | | |
1499 | 1533 | | |
1500 | 1534 | | |
| |||
2905 | 2939 | | |
2906 | 2940 | | |
2907 | 2941 | | |
2908 | | - | |
2909 | | - | |
2910 | | - | |
2911 | | - | |
2912 | | - | |
2913 | | - | |
2914 | | - | |
2915 | | - | |
2916 | | - | |
2917 | | - | |
2918 | | - | |
2919 | | - | |
2920 | | - | |
2921 | | - | |
2922 | | - | |
2923 | | - | |
2924 | | - | |
2925 | | - | |
2926 | | - | |
2927 | | - | |
2928 | | - | |
2929 | | - | |
2930 | | - | |
2931 | | - | |
2932 | | - | |
2933 | | - | |
| 2942 | + | |
| 2943 | + | |
2934 | 2944 | | |
2935 | 2945 | | |
2936 | 2946 | | |
2937 | 2947 | | |
2938 | 2948 | | |
2939 | 2949 | | |
2940 | | - | |
| 2950 | + | |
2941 | 2951 | | |
2942 | 2952 | | |
2943 | 2953 | | |
| |||
2950 | 2960 | | |
2951 | 2961 | | |
2952 | 2962 | | |
2953 | | - | |
2954 | | - | |
2955 | | - | |
2956 | | - | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
2957 | 2966 | | |
2958 | 2967 | | |
2959 | 2968 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
| 326 | + | |
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
| 340 | + | |
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | | - | |
| 349 | + | |
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
354 | | - | |
355 | | - | |
| 354 | + | |
356 | 355 | | |
357 | 356 | | |
358 | 357 | | |
| |||
364 | 363 | | |
365 | 364 | | |
366 | 365 | | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
| 366 | + | |
373 | 367 | | |
374 | 368 | | |
375 | 369 | | |
| |||
0 commit comments