code: def _watch_app_state(callback: Callable):
      """Start the process that serves the UI at the given hostname and port number.
  
      Arguments:
          callback: A function to run when the App state changes. Must be thread safe.
  
      Example:
  
          .. code-block:: python
  
              def handle_state_change():
                  print("The App State changed.")
                  watch_app_state(handle_state_change)
  
      """
      _CALLBACKS.append(callback)
      _start_websocket()
  
file_path: pytorch-lightning/src/lightning/app/frontend/panel/app_state_comm.py
imports: from __future__ import annotations
  import asyncio
  import os
  from threading import Thread
  from typing import Callable
  import websockets
  from lightning.app.core.constants import APP_SERVER_PORT
  from lightning.app.utilities.app_helpers import Logger
label_desc: Use image node_id 6 for calling a global function with example usage: _watch_app_state(callback) without return types