1- import asyncio
21import atexit
32import datetime
43import importlib .util
1817from rich .table import Table
1918
2019from . import flow , lib , setting
21- from .runtime import execution_context
2220from .setup import apply_setup_changes , drop_setup , flow_names_with_setup , sync_setup
2321
2422# Create ServerSettings lazily upon first call, as environment variables may be loaded from files, etc.
@@ -521,6 +519,15 @@ def server(
521519 APP_TARGET: path/to/app.py or installed_module.
522520 """
523521 app_ref = _get_app_ref_from_specifier (app_target )
522+ args = (
523+ app_ref ,
524+ address ,
525+ cors_origin ,
526+ cors_cocoindex ,
527+ cors_local ,
528+ live_update ,
529+ quiet ,
530+ )
524531
525532 if reload :
526533 watch_paths = {os .getcwd ()}
@@ -537,31 +544,15 @@ def server(
537544 watchfiles .run_process (
538545 * watch_paths ,
539546 target = _reloadable_server_target ,
540- args = (
541- app_ref ,
542- address ,
543- cors_origin ,
544- cors_cocoindex ,
545- cors_local ,
546- live_update ,
547- quiet ,
548- ),
547+ args = args ,
549548 watch_filter = watchfiles .PythonFilter (),
550549 callback = lambda changes : click .secho (
551550 f"\n Detected changes in { len (changes )} file(s), reloading server...\n " ,
552551 fg = "cyan" ,
553552 ),
554553 )
555554 else :
556- _run_server (
557- app_ref ,
558- address = address ,
559- cors_origin = cors_origin ,
560- cors_cocoindex = cors_cocoindex ,
561- cors_local = cors_local ,
562- live_update = live_update ,
563- quiet = quiet ,
564- )
555+ _run_server (* args )
565556
566557
567558def _reloadable_server_target (* args : Any , ** kwargs : Any ) -> None :
@@ -611,12 +602,9 @@ def _run_server(
611602 def handle_signal (signum : int , frame : FrameType | None ) -> None :
612603 shutdown_event .set ()
613604
614- async def _wait_for_shutdown_signal () -> None :
615- await asyncio .to_thread (shutdown_event .wait )
616-
617605 signal .signal (signal .SIGINT , handle_signal )
618606 signal .signal (signal .SIGTERM , handle_signal )
619- execution_context . run ( _wait_for_shutdown_signal () )
607+ shutdown_event . wait ( )
620608
621609
622610def _flow_name (name : str | None ) -> str :
0 commit comments