code: def test_shutsdown_cleanly(loop):
      port = open_port()
      with concurrent.futures.ThreadPoolExecutor() as tpe:
          subprocess_fut = tpe.submit(
              subprocess.run,
              [
                  "dask",
                  "scheduler",
                  "--jupyter",
                  "--no-dashboard",
                  "--host",
                  f"127.0.0.1:{port}",
              ],
              check=True,
              capture_output=True,
              timeout=10,
              encoding="utf8",
          )
  
          # wait until scheduler is running
          with Client(f"127.0.0.1:{port}", loop=loop):
              pass
  
          with requests.Session() as session:
              session.get(
                  "http://127.0.0.1:8787/jupyter/lab"
              ).raise_for_status()
              session.post(
                  "http://127.0.0.1:8787/jupyter/api/shutdown",
                  headers={"X-XSRFToken": session.cookies["_xsrf"]},
              ).raise_for_status()
  
          stderr = subprocess_fut.result().stderr
          assert "Traceback" not in stderr
          assert (
              "distributed.scheduler - INFO - Scheduler closing due to shutdown "
              "requested via Jupyter...\n" in stderr
          )
          assert "Shutting down on /api/shutdown request.\n" in stderr
          assert (
              "distributed.scheduler - INFO - Stopped scheduler at "
              f"'tcp://127.0.0.1:{port}'\n" in stderr
          )
          assert stderr.endswith(
              "distributed.scheduler - INFO - End scheduler\n"
          )
  
file_path: distributed/distributed/tests/test_jupyter.py
imports: from __future__ import annotations
  import asyncio
  import concurrent.futures
  import subprocess
  from datetime import datetime, timedelta, timezone
  from time import perf_counter
  import pytest
  from tornado.httpclient import AsyncHTTPClient
  from distributed import Client, Scheduler
  from distributed.core import Status
  from distributed.utils import open_port
  from distributed.utils_test import gen_test, popen
  import requests
label_desc: Use image node_id 2 for calling a global function with example usage: test_shutsdown_cleanly(loop) without return types