@@ -118,7 +118,7 @@ def flush(self):
118
118
119
119
def sync_flush_1d_array (np_buffer , zarr_array , offset ):
120
120
zarr_array [offset : offset + np_buffer .shape [0 ]] = np_buffer
121
- update_progress (1 )
121
+ update_progress (np_buffer . nbytes )
122
122
123
123
124
124
def sync_flush_2d_array (np_buffer , zarr_array , offset ):
@@ -127,12 +127,15 @@ def sync_flush_2d_array(np_buffer, zarr_array, offset):
127
127
# encoder implementations.
128
128
s = slice (offset , offset + np_buffer .shape [0 ])
129
129
chunk_width = zarr_array .chunks [1 ]
130
+ # TODO use zarr chunks here to support non-uniform chunking later
131
+ # and for simplicity
130
132
zarr_array_width = zarr_array .shape [1 ]
131
133
start = 0
132
134
while start < zarr_array_width :
133
135
stop = min (start + chunk_width , zarr_array_width )
134
- zarr_array [s , start :stop ] = np_buffer [:, start :stop ]
135
- update_progress (1 )
136
+ chunk_buffer = np_buffer [:, start :stop ]
137
+ zarr_array [s , start :stop ] = chunk_buffer
138
+ update_progress (chunk_buffer .nbytes )
136
139
start = stop
137
140
138
141
@@ -177,15 +180,15 @@ def __init__(self, worker_processes=1, progress_config=None):
177
180
self .executor = cf .ProcessPoolExecutor (
178
181
max_workers = worker_processes ,
179
182
)
180
- self .futures = []
183
+ self .futures = set ()
181
184
182
185
set_progress (0 )
183
186
if progress_config is None :
184
187
progress_config = ProgressConfig ()
185
188
self .progress_config = progress_config
186
189
self .progress_bar = tqdm .tqdm (
187
190
total = progress_config .total ,
188
- desc = f"{ progress_config .title :>9 } " ,
191
+ desc = f"{ progress_config .title :>7 } " ,
189
192
unit_scale = True ,
190
193
unit = progress_config .units ,
191
194
smoothing = 0.1 ,
@@ -216,7 +219,19 @@ def _update_progress_worker(self):
216
219
logger .debug ("Exit progress thread" )
217
220
218
221
def submit (self , * args , ** kwargs ):
219
- self .futures .append (self .executor .submit (* args , ** kwargs ))
222
+ future = self .executor .submit (* args , ** kwargs )
223
+ self .futures .add (future )
224
+ return future
225
+
226
+ def wait_for_completed (self , timeout = None ):
227
+ done , not_done = cf .wait (self .futures , timeout , cf .FIRST_COMPLETED )
228
+ for future in done :
229
+ exception = future .exception ()
230
+ # TODO do the check for BrokenProcessPool here
231
+ if exception is not None :
232
+ raise exception
233
+ self .futures = not_done
234
+ return done
220
235
221
236
def results_as_completed (self ):
222
237
for future in cf .as_completed (self .futures ):
0 commit comments