@@ -148,7 +148,7 @@ def sample_spatial_and_temporal_locations_for_examples(
148148
149149 return locations
150150
151- def create_batches (self ) -> None :
151+ def create_batches (self , use_async : Optional [ bool ] = True ) -> None :
152152 """Create batches (if necessary).
153153
154154 Make dirs: `<output_data.filepath> / <split_name> / <data_source_name>`.
@@ -216,33 +216,38 @@ def create_batches(self) -> None:
216216 f"About to submit create_batches task for { data_source_name } , { split_name } "
217217 )
218218
219- # Sometimes when debuggin it is easy to use non async
220- # data_source.create_batches(**kwargs_for_create_batches)
221-
222- async_result = pool .apply_async (
223- data_source .create_batches ,
224- kwds = kwargs_for_create_batches ,
225- callback = partial (
226- callback , data_source_name = data_source_name , split_name = split_name
227- ),
228- error_callback = partial (
229- error_callback ,
230- data_source_name = data_source_name ,
231- split_name = split_name ,
232- an_error_has_occured = an_error_has_occured ,
233- ),
234- )
235- async_results_from_create_batches .append (async_result )
236-
237- # Wait for all async_results to finish:
238- for async_result in async_results_from_create_batches :
239- async_result .wait ()
240- if an_error_has_occured .is_set ():
241- # An error has occurred but, at this point in the code, we don't know which
242- # worker process raised the exception. But, with luck, the worker process
243- # will have logged an informative exception via the _error_callback func.
244- raise RuntimeError (
245- f"A worker process raised an exception whilst working on { split_name } !"
219+ if ~ use_async :
220+ # Sometimes when debuggin it is easy to use non async
221+ data_source .create_batches (** kwargs_for_create_batches )
222+ else :
223+
224+ async_result = pool .apply_async (
225+ data_source .create_batches ,
226+ kwds = kwargs_for_create_batches ,
227+ callback = partial (
228+ callback , data_source_name = data_source_name , split_name = split_name
229+ ),
230+ error_callback = partial (
231+ error_callback ,
232+ data_source_name = data_source_name ,
233+ split_name = split_name ,
234+ an_error_has_occured = an_error_has_occured ,
235+ ),
246236 )
237+ async_results_from_create_batches .append (async_result )
238+
239+ # Wait for all async_results to finish:
240+ for async_result in async_results_from_create_batches :
241+ async_result .wait ()
242+ if an_error_has_occured .is_set ():
243+ # An error has occurred but, at this point in the code,
244+ # we don't know which worker process raised the exception.
245+ # But, with luck, the worker process
246+ # will have logged an informative exception via the
247+ # _error_callback func.
248+ raise RuntimeError (
249+ f"A worker process raised an exception whilst "
250+ f"working on { split_name } !"
251+ )
247252
248253 logger .info (f"Finished creating batches for { split_name } !" )
0 commit comments