@@ -160,6 +160,7 @@ def populate(
160
160
display_progress = False ,
161
161
processes = 1 ,
162
162
make_kwargs = None ,
163
+ return_success_count = False
163
164
):
164
165
"""
165
166
``table.populate()`` calls ``table.make(key)`` for every primary key in
@@ -217,6 +218,7 @@ def handler(signum, frame):
217
218
processes = min (_ for _ in (processes , nkeys , mp .cpu_count ()) if _ )
218
219
219
220
error_list = []
221
+ success_list = []
220
222
populate_kwargs = dict (
221
223
suppress_errors = suppress_errors ,
222
224
return_exception_objects = return_exception_objects ,
@@ -227,9 +229,12 @@ def handler(signum, frame):
227
229
for key in (
228
230
tqdm (keys , desc = self .__class__ .__name__ ) if display_progress else keys
229
231
):
230
- error = self ._populate1 (key , jobs , ** populate_kwargs )
231
- if error is not None :
232
- error_list .append (error )
232
+ status = self ._populate1 (key , jobs , ** populate_kwargs )
233
+ if status is not None :
234
+ if isinstance (status , tuple ):
235
+ error_list .append (status )
236
+ elif status :
237
+ success_list .append (1 )
233
238
else :
234
239
# spawn multiple processes
235
240
self .connection .close () # disconnect parent process from MySQL server
@@ -241,9 +246,12 @@ def handler(signum, frame):
241
246
if display_progress
242
247
else contextlib .nullcontext ()
243
248
) as progress_bar :
244
- for error in pool .imap (_call_populate1 , keys , chunksize = 1 ):
245
- if error is not None :
246
- error_list .append (error )
249
+ for status in pool .imap (_call_populate1 , keys , chunksize = 1 ):
250
+ if status is not None :
251
+ if isinstance (status , tuple ):
252
+ error_list .append (status )
253
+ elif status :
254
+ success_list .append (1 )
247
255
if display_progress :
248
256
progress_bar .update ()
249
257
self .connection .connect () # reconnect parent process to MySQL server
@@ -252,8 +260,12 @@ def handler(signum, frame):
252
260
if reserve_jobs :
253
261
signal .signal (signal .SIGTERM , old_handler )
254
262
263
+ if suppress_errors and return_success_count :
264
+ return sum (success_list ), error_list
255
265
if suppress_errors :
256
266
return error_list
267
+ if return_success_count :
268
+ return sum (success_list )
257
269
258
270
def _populate1 (
259
271
self , key , jobs , suppress_errors , return_exception_objects , make_kwargs = None
@@ -311,6 +323,7 @@ def _populate1(
311
323
)
312
324
if jobs is not None :
313
325
jobs .complete (self .target .table_name , self ._job_key (key ))
326
+ return True
314
327
finally :
315
328
self .__class__ ._allow_insert = False
316
329
0 commit comments