restart.py 638 B

12345678910111213141516171819202122232425
  1. import os
  2. from pathlib import Path
  3. from modules.paths_internal import script_path
  4. def is_restartable() -> bool:
  5. """
  6. Return True if the webui is restartable (i.e. there is something watching to restart it with)
  7. """
  8. return bool(os.environ.get('SD_WEBUI_RESTART'))
  9. def restart_program() -> None:
  10. """creates file tmp/restart and immediately stops the process, which webui.bat/webui.sh interpret as a command to start webui again"""
  11. tmpdir = Path(script_path) / "tmp"
  12. tmpdir.mkdir(parents=True, exist_ok=True)
  13. (tmpdir / "restart").touch()
  14. stop_program()
  15. def stop_program() -> None:
  16. os._exit(0)