@@ -320,6 +320,7 @@ def preprocess_splits(
320320 gen_kwargs : Optional [dict [str , dict [str , Any ]]] = None ,
321321 num_proc : int = 1 ,
322322 verbose : bool = True ,
323+ worker_initializer : Optional [Callable [[], None ]] = None ,
323324) -> tuple [
324325 dict [str , set [str ]],
325326 dict [str , dict [str , Any ]],
@@ -349,6 +350,8 @@ def preprocess_splits(
349350 Number of worker processes to use for shard-level parallelism. Defaults to 1.
350351 verbose (bool, optional):
351352 If True, displays progress bars. Defaults to True.
353+ worker_initializer (callable, optional):
354+ Callable executed once when each worker process starts. Defaults to None.
352355
353356 Returns:
354357 tuple:
@@ -400,7 +403,7 @@ def preprocess_splits(
400403 shards_data = []
401404
402405 try :
403- with mp .Pool (n_proc ) as pool :
406+ with mp .Pool (n_proc , initializer = worker_initializer ) as pool :
404407 results = [
405408 pool .apply_async (
406409 _process_shard_debug ,
@@ -522,6 +525,7 @@ def preprocess(
522525 gen_kwargs : Optional [dict [str , dict [str , Any ]]] = None ,
523526 num_proc : int = 1 ,
524527 verbose : bool = True ,
528+ worker_initializer : Optional [Callable [[], None ]] = None ,
525529) -> tuple [
526530 dict [str , dict [str , Any ]],
527531 dict [str , Any ],
@@ -536,6 +540,9 @@ def preprocess(
536540 gen_kwargs: Optional generator kwargs for parallel processing.
537541 num_proc: Number of processes.
538542 verbose: Whether to show progress.
543+ worker_initializer: Optional callable executed once when each worker
544+ process starts. It must be picklable when using the ``spawn`` start
545+ method.
539546
540547 Returns:
541548 tuple: A 5-tuple ``(split_flat_cst, variable_schema, constant_schema,
@@ -548,7 +555,13 @@ def preprocess(
548555 global_cgns_types ,
549556 global_feature_types ,
550557 split_n_samples ,
551- ) = preprocess_splits (generators , gen_kwargs , num_proc , verbose )
558+ ) = preprocess_splits (
559+ generators ,
560+ gen_kwargs ,
561+ num_proc ,
562+ verbose ,
563+ worker_initializer ,
564+ )
552565
553566 # --- build features ---
554567 var_features = sorted (list (set ().union (* split_var_path .values ())))
0 commit comments