shutdown_hard

Documentation for eth_defi.utils.shutdown_hard function.

shutdown_hard(process, log_level=None, block=True, block_timeout=30, check_port=None, graceful_timeout=0.0)

Kill Psutil process.

  • Optionally ask the process to exit cleanly first (graceful_timeout), then fall back to OS SIGKILL

  • Log output if necessary

  • Use port listening to check that the process goes down and frees its ports

Parameters
  • graceful_timeout (float) – When greater than zero, send SIGTERM and wait up to this many seconds for the process to exit on its own before SIGKILL. This lets a process flush on-disk state — critically, Anvil only writes its fork RPC cache (~/.foundry/cache/rpc/<network>/<block>/storage.json) on a graceful shutdown; a straight SIGKILL discards it, so a warm cache never accumulates. Defaults to 0.0 (immediate SIGKILL) to preserve the fast, hang-proof behaviour for callers that do not need the flush.

  • process (psutil.Popen) – Process to kill

  • block –

    Block the execution until the process has terminated.

    You must give check_port option to ensure we enforce the shutdown.

  • block_timeout – How long we give for process to clean up after itself

  • log_level (Optional[int]) – If set, dump anything in Anvil stdout to the Python logging using level INFO.

  • check_port (Optional[int]) – Check that TCP/IP localhost port is freed after shutdown

Returns

stdout, stderr as string

Return type

tuple[bytes, bytes]