@@ -319,7 +319,6 @@ def build_udf_endpoint(
319319
320320 async def do_func (
321321 cancel_event : threading .Event ,
322- finished_event : threading .Event ,
323322 timer : Timer ,
324323 row_ids : Sequence [int ],
325324 rows : Sequence [Sequence [Any ]],
@@ -333,7 +332,6 @@ async def do_func(
333332 out .append (await func (* row ))
334333 else :
335334 out .append (func (* row ))
336- finished_event .set ()
337335 return row_ids , list (zip (out ))
338336
339337 return do_func
@@ -367,7 +365,6 @@ def build_vector_udf_endpoint(
367365
368366 async def do_func (
369367 cancel_event : threading .Event ,
370- finished_event : threading .Event ,
371368 timer : Timer ,
372369 row_ids : Sequence [int ],
373370 cols : Sequence [Tuple [Sequence [Any ], Optional [Sequence [bool ]]]],
@@ -391,7 +388,6 @@ async def do_func(
391388 else :
392389 out = func ()
393390
394- finished_event .set ()
395391 cancel_on_event (cancel_event )
396392
397393 # Single masked value
@@ -434,7 +430,6 @@ def build_tvf_endpoint(
434430
435431 async def do_func (
436432 cancel_event : threading .Event ,
437- finished_event : threading .Event ,
438433 timer : Timer ,
439434 row_ids : Sequence [int ],
440435 rows : Sequence [Sequence [Any ]],
@@ -452,7 +447,6 @@ async def do_func(
452447 res = func (* row )
453448 out .extend (as_list_of_tuples (res ))
454449 out_ids .extend ([row_ids [i ]] * (len (out )- len (out_ids )))
455- finished_event .set ()
456450 return out_ids , out
457451
458452 return do_func
@@ -485,7 +479,6 @@ def build_vector_tvf_endpoint(
485479
486480 async def do_func (
487481 cancel_event : threading .Event ,
488- finished_event : threading .Event ,
489482 timer : Timer ,
490483 row_ids : Sequence [int ],
491484 cols : Sequence [Tuple [Sequence [Any ], Optional [Sequence [bool ]]]],
@@ -517,8 +510,6 @@ async def do_func(
517510 else :
518511 func_res = func ()
519512
520- finished_event .set ()
521-
522513 res = get_dataframe_columns (func_res )
523514
524515 cancel_on_event (cancel_event )
@@ -981,6 +972,12 @@ async def __call__(
981972 datetime .timezone .utc ,
982973 ).strftime ('%Y-%m-%dT%H:%M:%S.%fZ' ),
983974 )
975+ call_timer = Timer (
976+ id = request_id ,
977+ timestamp = datetime .datetime .now (
978+ datetime .timezone .utc ,
979+ ).strftime ('%Y-%m-%dT%H:%M:%S.%fZ' ),
980+ )
984981
985982 assert scope ['type' ] == 'http'
986983
@@ -997,6 +994,7 @@ async def __call__(
997994 func_endpoint = self .endpoints .get (func_name )
998995
999996 timer .metadata ['function' ] = func_name .decode ('utf-8' ) if func_name else ''
997+ call_timer .metadata ['function' ] = timer .metadata ['function' ]
1000998
1001999 func = None
10021000 func_info : Dict [str , Any ] = {}
@@ -1037,23 +1035,18 @@ async def __call__(
10371035 result = []
10381036
10391037 cancel_event = threading .Event ()
1040- finished_event = threading .Event ()
1041-
1042- # Async functions don't need to set the finished event
1043- if func_info ['is_async' ]:
1044- finished_event .set ()
10451038
10461039 with timer ('parse_input' ):
10471040 inputs = input_handler ['load' ]( # type: ignore
10481041 func_info ['colspec' ], b'' .join (data ),
10491042 )
10501043
10511044 func_task = asyncio .create_task (
1052- func (cancel_event , finished_event , timer , * inputs )
1045+ func (cancel_event , call_timer , * inputs )
10531046 if func_info ['is_async' ]
10541047 else to_thread (
10551048 lambda : asyncio .run (
1056- func (cancel_event , finished_event , timer , * inputs ),
1049+ func (cancel_event , call_timer , * inputs ),
10571050 ),
10581051 ),
10591052 )
@@ -1073,9 +1066,6 @@ async def __call__(
10731066
10741067 await cancel_all_tasks (pending )
10751068
1076- # Make sure threads finish before we proceed
1077- finished_event .wait ()
1078-
10791069 for task in done :
10801070 if task is disconnect_task :
10811071 cancel_event .set ()
@@ -1163,6 +1153,9 @@ async def __call__(
11631153 out ['body' ] = body
11641154 await send (out )
11651155
1156+ for k , v in call_timer .metrics .items ():
1157+ timer .metrics [k ] = v
1158+
11661159 timer .finish ()
11671160
11681161 def _create_link (
0 commit comments