INNER CODE UNIT · Python

_close_sessions_at_exit

feder-cr/Jobs_Applier_AI_Agent_AIHawk · src/aihawk/mcp/server.py:73

def _close_sessions_at_exit() -> None:
    """Best effort shutdown of every browser when the process itself ends,
    for the HTTP transport, where the lifespan cannot do it.

    A browser left behind is not a small leak here: Firefox launches a whole
    tree of processes, and an orphaned one goes on holding its profile
    directory and its port. Bounded, because this runs in a fresh event loop
    and an await on an object from the finished one does not return: ten
    seconds, then the process is allowed to end.
    """
    try:
        asyncio.run(asyncio.wait_for(registry.close_all(), 10))
    except Exception:
        pass


atexit.register(_close_sessions_at_exit)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…