@@ -289,11 +289,12 @@ def process_args() -> Namespace:
289289
290290
291291def _init () -> Namespace :
292- if not server .initialized :
293- new_args = process_args ()
294- _initialize_optimizer (new_args )
295- server .initialized = True
296- return server .args
292+ if server .initialized :
293+ return server .args
294+ new_args = process_args ()
295+ _initialize_optimizer (new_args )
296+ server .initialized = True
297+ return new_args
297298
298299
299300@server .feature ("apiKeyExistsAndValid" )
@@ -417,13 +418,13 @@ def initialize_function_optimization(params: FunctionOptimizationInitParams) ->
417418async def perform_function_optimization (params : FunctionOptimizationParams ) -> dict [str , str ]:
418419 with execution_context (task_id = params .task_id ):
419420 loop = asyncio .get_running_loop ()
420- server . cancel_event = threading .Event ()
421+ cancel_event = threading .Event ()
421422
422423 try :
423424 ctx = contextvars .copy_context ()
424- return await loop .run_in_executor (None , ctx .run , sync_perform_optimization , server , params )
425+ return await loop .run_in_executor (None , ctx .run , sync_perform_optimization , server , cancel_event , params )
425426 except asyncio .CancelledError :
426- server . cancel_event .set ()
427+ cancel_event .set ()
427428 return get_cancelled_reponse ()
428429 finally :
429430 server .cleanup_the_optimizer ()
0 commit comments