@@ -304,7 +304,6 @@ async def run_in_parallel(
304304 func : Callable [..., Any ],
305305 params_list : Sequence [Sequence [Any ]],
306306 cancel_event : threading .Event ,
307- limit : int = get_option ('external_function.concurrency_limit' ),
308307 transformer : Callable [[Any ], Any ] = identity ,
309308) -> List [Any ]:
310309 """"
@@ -318,8 +317,6 @@ async def run_in_parallel(
318317 The parameters to pass to the function
319318 cancel_event : threading.Event
320319 The event to check for cancellation
321- limit : int
322- The maximum number of concurrent tasks to run
323320 transformer : Callable[[Any], Any]
324321 A function to transform the results
325322
@@ -329,6 +326,7 @@ async def run_in_parallel(
329326 The results of the function calls
330327
331328 """
329+ limit = get_concurrency_limit (func )
332330 is_async = asyncio .iscoroutinefunction (func )
333331
334332 async def call (batch : Sequence [Any ]) -> Any :
@@ -355,6 +353,29 @@ async def thread_call(batch: Sequence[Any]) -> Any:
355353 return list (itertools .chain .from_iterable (results ))
356354
357355
356+ def get_concurrency_limit (func : Callable [..., Any ]) -> int :
357+ """
358+ Get the concurrency limit for a function.
359+
360+ Parameters
361+ ----------
362+ func : Callable
363+ The function to get the concurrency limit for
364+
365+ Returns
366+ -------
367+ int
368+ The concurrency limit for the function
369+
370+ """
371+ return max (
372+ 1 , func ._singlestoredb_attrs .get ( # type: ignore
373+ 'concurrency_limit' ,
374+ get_option ('external_function.concurrency_limit' ),
375+ ),
376+ )
377+
378+
358379def build_udf_endpoint (
359380 func : Callable [..., Any ],
360381 returns_data_format : str ,
0 commit comments