Skip to content

Commit

Permalink
Added back missing sleep() after application start
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Jan 23, 2024
1 parent 390f315 commit 294f744
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/asphalt/core/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
create_task_group,
fail_after,
get_cancelled_exc_class,
sleep,
to_thread,
)
from anyio.abc import TaskStatus
Expand Down Expand Up @@ -113,28 +114,26 @@ async def run_application(
async with AsyncExitStack() as exit_stack:
handlers = {ApplicationExit: handle_application_exit}
exit_stack.enter_context(catch(handlers)) # type: ignore[arg-type]
# if platform.system() != "Windows":
# root_tg = await exit_stack.enter_async_context(create_task_group())
# await root_tg.start(handle_signals, name="Asphalt signal handler")
# exit_stack.callback(root_tg.cancel_scope.cancel)

# ctx = await exit_stack.enter_async_context(Context())
async with create_task_group() as root_tg, Context() as ctx:
if platform.system() != "Windows":
await root_tg.start(handle_signals, name="Asphalt signal handler")
try:
with fail_after(start_timeout):
await component.start(ctx)
except TimeoutError:
logger.error("Timeout waiting for the root component to start")
raise
except (ApplicationExit, get_cancelled_exc_class()):
logger.error("Application startup interrupted")
return
except BaseException:
logger.exception("Error during application startup")
raise
if platform.system() != "Windows":
root_tg = await exit_stack.enter_async_context(create_task_group())
await root_tg.start(handle_signals, name="Asphalt signal handler")
exit_stack.callback(root_tg.cancel_scope.cancel)

ctx = await exit_stack.enter_async_context(Context())
try:
with fail_after(start_timeout):
await component.start(ctx)
except TimeoutError:
logger.error("Timeout waiting for the root component to start")
raise
except (ApplicationExit, get_cancelled_exc_class()):
logger.error("Application startup interrupted")
return
except BaseException:
logger.exception("Error during application startup")
raise

logger.info("Application started")
await sleep(float("inf"))
finally:
logger.info("Application stopped")

0 comments on commit 294f744

Please sign in to comment.