@@ -301,7 +301,6 @@ async def run_in_parallel(
301301 func : Callable [..., Any ],
302302 params_list : Sequence [Sequence [Any ]],
303303 cancel_event : threading .Event ,
304- limit : int = get_option ('external_function.concurrency_limit' ),
305304 transformer : Callable [[Any ], Any ] = identity ,
306305) -> List [Any ]:
307306 """"
@@ -315,8 +314,6 @@ async def run_in_parallel(
315314 The parameters to pass to the function
316315 cancel_event : threading.Event
317316 The event to check for cancellation
318- limit : int
319- The maximum number of concurrent tasks to run
320317 transformer : Callable[[Any], Any]
321318 A function to transform the results
322319
@@ -326,6 +323,7 @@ async def run_in_parallel(
326323 The results of the function calls
327324
328325 """
326+ limit = get_concurrency_limit (func )
329327 is_async = asyncio .iscoroutinefunction (func )
330328
331329 async def call (batch : Sequence [Any ]) -> Any :
@@ -352,6 +350,29 @@ async def thread_call(batch: Sequence[Any]) -> Any:
352350 return list (itertools .chain .from_iterable (results ))
353351
354352
353+ def get_concurrency_limit (func : Callable [..., Any ]) -> int :
354+ """
355+ Get the concurrency limit for a function.
356+
357+ Parameters
358+ ----------
359+ func : Callable
360+ The function to get the concurrency limit for
361+
362+ Returns
363+ -------
364+ int
365+ The concurrency limit for the function
366+
367+ """
368+ return max (
369+ 1 , func ._singlestoredb_attrs .get ( # type: ignore
370+ 'concurrency_limit' ,
371+ get_option ('external_function.concurrency_limit' ),
372+ ),
373+ )
374+
375+
355376def build_udf_endpoint (
356377 func : Callable [..., Any ],
357378 returns_data_format : str ,
0 commit comments