code: def number_of_sanic_workers(
      lock_store: Union[EndpointConfig, LockStore, None]
  ) -> int:
      """Get the number of Sanic workers to use in `app.run()`.
  
      If the environment variable constants.ENV_SANIC_WORKERS is set and is not equal to
      1, that value will only be permitted if the used lock store is not the
      `InMemoryLockStore`.
      """
  
      def _log_and_get_default_number_of_workers() -> int:
          logger.debug(
              f"Using the default number of Sanic workers ({DEFAULT_SANIC_WORKERS})."
          )
          return DEFAULT_SANIC_WORKERS
  
      try:
          env_value = int(
              os.environ.get(ENV_SANIC_WORKERS, DEFAULT_SANIC_WORKERS)
          )
      except ValueError:
          logger.error(
              f"Cannot convert environment variable `{ENV_SANIC_WORKERS}` "
              f"to int ('{os.environ[ENV_SANIC_WORKERS]}')."
          )
          return _log_and_get_default_number_of_workers()
  
      if env_value == DEFAULT_SANIC_WORKERS:
          return _log_and_get_default_number_of_workers()
  
      if env_value < 1:
          logger.debug(
              f"Cannot set number of Sanic workers to the desired value "
              f"({env_value}). The number of workers must be at least 1."
          )
          return _log_and_get_default_number_of_workers()
  
      if _lock_store_is_multi_worker_compatible(lock_store):
          logger.debug(f"Using {env_value} Sanic workers.")
          return env_value
  
      logger.debug(
          f"Unable to assign desired number of Sanic workers ({env_value}) as "
          f"no `RedisLockStore` or custom `LockStore` endpoint "
          f"configuration has been found."
      )
      return _log_and_get_default_number_of_workers()
  
imports: import json
  import logging
  import os
  from decimal import Decimal
  from pathlib import Path
  from typing import Any, Dict, Optional, Set, Text, Tuple, Union
  import numpy
  import rasa.shared.utils.io
  from rasa.constants import DEFAULT_SANIC_WORKERS, ENV_SANIC_WORKERS
  from rasa.shared.constants import DEFAULT_ENDPOINTS_PATH, TCP_PROTOCOL
  from rasa.core.lock_store import LockStore, RedisLockStore, InMemoryLockStore
  from rasa.utils.endpoints import EndpointConfig, read_endpoint_config
  from sanic import Sanic
  from socket import SOCK_DGRAM, SOCK_STREAM
  import rasa.cli.utils
label_desc: Use image node_id 12 for calling a global function with example usage: number_of_sanic_workers(lock_store) and returns: _log_and_get_default_number_of_workers, DEFAULT_SANIC_WORKERS, _log_and_get_default_number_of_workers, _log_and_get_default_number_of_workers, env_value, _log_and_get_default_number_of_workers