code: def ManagedServerLoop(unused_tcp_port: int) -> MSL:
      @contextmanager
      def msl(
          application: Application,
          port: int | None = None,
          **server_kwargs: Any,
      ) -> Iterator[Server]:
          if port is None:
              port = unused_tcp_port
          server = Server(application, port=port, **server_kwargs)
          server.start()
          yield server
          server.unlisten()
          server.stop()
  
      return msl
  
file_path: bokeh/tests/support/plugins/managed_server_loop.py
imports: from __future__ import annotations
  import logging
  from contextlib import contextmanager
  from typing import TYPE_CHECKING, Any, ContextManager, Iterator, Protocol
  import pytest
  from bokeh.server.server import Server
label_desc: Use image node_id 1 for calling a global function with example usage: ManagedServerLoop(unused_tcp_port) and returns: msl