code: def temporary_server(
      env: ServeEnv,
      forecaster_type: Optional[Type[Predictor]],
      settings: Settings = Settings(),
  ) -> ContextManager[ServerFacade]:
      """
      A context manager that instantiates a Gunicorn inference server in a
      separate process (using the :func:`make_inference_server` call)
  
      Parameters
      ----------
      env
          The `ServeEnv` to use in static inference mode.
          Either `env` or `forecaster_type` must be set.
      forecaster_type
          The `Predictor` type to use in dynamic inference mode.
          Either `env` or `forecaster_type` must be set.
      settings
          Settings to use when instantiating the Gunicorn server.
  
      Returns
      -------
      ContextManager[ServerFacade]
          A context manager that yields the `InferenceServer` instance
          wrapping the spawned inference server.
      """
      context = multiprocessing.get_context("spawn")
      context = typing.cast(
          ForkContext, context
      )  # cast to make mypi pass
  
      server = Server(env, forecaster_type, settings)
      process = context.Process(target=server.run)
      process.start()
  
      endpoint = ServerFacade(
          base_address="http://{address}:{port}".format(
              address=settings.sagemaker_server_address,
              port=settings.sagemaker_server_port,
          )
      )
  
      # try to ping the server (signalling liveness)
      # poll for n seconds in t second intervals
      n, t = 10, 2
      max_time = time.time() + n
      while not endpoint.ping():
          if time.time() < max_time:
              time.sleep(t)
          else:
              msg = f"Failed to start the inference server within {n} seconds"
              raise TimeoutError(msg)
  
      yield endpoint
  
      process.terminate()
      process.join()
  
imports: import json
  import multiprocessing
  import socket
  import tempfile
  import time
  import typing
  import waitress
  from contextlib import closing, contextmanager
  from dataclasses import dataclass
  from multiprocessing.context import ForkContext
  from pathlib import Path
  from typing import Any, ContextManager, Dict, Iterable, List, Optional, Type
  import requests
  from gluonts.dataset.common import DataEntry
  from gluonts.dataset.jsonl import encode_json
  from gluonts.dataset.repository.datasets import materialize_dataset
  from gluonts.model.predictor import Predictor
  from gluonts.shell.env import ServeEnv, TrainEnv
  from gluonts.shell.sagemaker import ServePaths, TrainPaths
  from gluonts.shell.sagemaker.params import encode_sagemaker_parameters
  from gluonts.shell.serve import Settings, make_flask_app
label_desc: Use image node_id 2 for calling a global function with example usage: temporary_server(env, forecaster_type, settings) without return types