code: def with_timeout(
      timeout: Union[float, datetime.timedelta],
      future: _Yieldable,
      quiet_exceptions: "Union[Type[Exception], Tuple[Type[Exception], ...]]" = (),
  ) -> Future:
      """Wraps a `.Future` (or other yieldable object) in a timeout.
  
      Raises `tornado.util.TimeoutError` if the input future does not
      complete before ``timeout``, which may be specified in any form
      allowed by `.IOLoop.add_timeout` (i.e. a `datetime.timedelta` or
      an absolute time relative to `.IOLoop.time`)
  
      If the wrapped `.Future` fails after it has timed out, the exception
      will be logged unless it is either of a type contained in
      ``quiet_exceptions`` (which may be an exception type or a sequence of
      types), or an ``asyncio.CancelledError``.
  
      The wrapped `.Future` is not canceled when the timeout expires,
      permitting it to be reused. `asyncio.wait_for` is similar to this
      function but it does cancel the wrapped `.Future` on timeout.
  
      .. versionadded:: 4.0
  
      .. versionchanged:: 4.1
         Added the ``quiet_exceptions`` argument and the logging of unhandled
         exceptions.
  
      .. versionchanged:: 4.4
         Added support for yieldable objects other than `.Future`.
  
      .. versionchanged:: 6.0.3
         ``asyncio.CancelledError`` is now always considered "quiet".
  
      .. versionchanged:: 6.2
         ``tornado.util.TimeoutError`` is now an alias to ``asyncio.TimeoutError``.
  
      """
      # It's tempting to optimize this by cancelling the input future on timeout
      # instead of creating a new one, but A) we can't know if we are the only
      # one waiting on the input future, so cancelling it might disrupt other
      # callers and B) concurrent futures can only be cancelled while they are
      # in the queue, so cancellation cannot reliably bound our waiting time.
      future_converted = convert_yielded(future)
      result = _create_future()
      chain_future(future_converted, result)
      io_loop = IOLoop.current()
  
      def error_callback(future: Future) -> None:
          try:
              future.result()
          except asyncio.CancelledError:
              pass
          except Exception as e:
              if not isinstance(e, quiet_exceptions):
                  app_log.error(
                      "Exception in Future %r after timeout",
                      future,
                      exc_info=True,
                  )
  
      def timeout_callback() -> None:
          if not result.done():
              result.set_exception(TimeoutError("Timeout"))
          # In case the wrapped future goes on to fail, log it.
          future_add_done_callback(future_converted, error_callback)
  
      timeout_handle = io_loop.add_timeout(timeout, timeout_callback)
      if isinstance(future_converted, Future):
          # We know this future will resolve on the IOLoop, so we don't
          # need the extra thread-safety of IOLoop.add_future (and we also
          # don't care about StackContext here.
          future_add_done_callback(
              future_converted,
              lambda future: io_loop.remove_timeout(timeout_handle),
          )
      else:
          # concurrent.futures.Futures may resolve on any thread, so we
          # need to route them back to the IOLoop.
          io_loop.add_future(
              future_converted,
              lambda future: io_loop.remove_timeout(timeout_handle),
          )
      return result
  
imports: import asyncio
  import builtins
  import collections
  from collections.abc import Generator
  import concurrent.futures
  import datetime
  import functools
  from functools import singledispatch
  from inspect import isawaitable
  import sys
  import types
  from tornado.concurrent import Future, is_future, chain_future, future_set_exc_info, future_add_done_callback, future_set_result_unless_cancelled
  from tornado.ioloop import IOLoop
  from tornado.log import app_log
  from tornado.util import TimeoutError
  import typing
  from typing import Union, Any, Callable, List, Type, Tuple, Awaitable, Dict, overload
label_desc: Use image node_id 11 for calling a global function with example usage: with_timeout(timeout, future, quiet_exceptions) and returns: result