|
53 | 53 | from zarr.meta import encode_array_metadata, encode_group_metadata |
54 | 54 | from zarr.util import (buffer_size, json_loads, nolock, normalize_chunks, |
55 | 55 | normalize_dtype, normalize_fill_value, normalize_order, |
56 | | - normalize_shape, normalize_storage_path) |
| 56 | + normalize_shape, normalize_storage_path, retry_call) |
57 | 57 |
|
58 | 58 | __doctest_requires__ = { |
59 | 59 | ('RedisStore', 'RedisStore.*'): ['redis'], |
@@ -859,22 +859,10 @@ def __setitem__(self, key, value): |
859 | 859 | temp_path = os.path.join(dir_path, temp_name) |
860 | 860 | try: |
861 | 861 | self._tofile(value, temp_path) |
862 | | - |
| 862 | + # move temporary file into place; |
863 | 863 | # make several attempts at writing the temporary file to get past |
864 | 864 | # potential antivirus file locking issues |
865 | | - attempts = 0 |
866 | | - while attempts < 10: |
867 | | - try: |
868 | | - # move temporary file into place |
869 | | - os.replace(temp_path, file_path) |
870 | | - break |
871 | | - except PermissionError: |
872 | | - # wait for file lock to release before attempting again |
873 | | - time.sleep(0.1) |
874 | | - attempts += 1 |
875 | | - if attempts == 10: |
876 | | - os.replace(temp_path, file_path) |
877 | | - |
| 865 | + retry_call(os.replace, temp_path, file_path) |
878 | 866 | finally: |
879 | 867 | # clean up if temp file still exists for whatever reason |
880 | 868 | if os.path.exists(temp_path): # pragma: no cover |
|
0 commit comments