parameters: (fut, timeout, *, loop=None)
docstring: Wait for the single Future or coroutine to complete, with timeout.
  
      Coroutine will be wrapped in Task.
  
      Returns result of the Future or coroutine.  When a timeout occurs,
      it cancels the task and raises TimeoutError.  To avoid the task
      cancellation, wrap it in shield().
  
      If the wait is cancelled, the task is also cancelled.
  
      This function is a coroutine.
docstring_summary: Wait for the single Future or coroutine to complete, with timeout.
docstring_tokens: Wait for the single Future or coroutine to complete with timeout .
function: async def wait_for(fut, timeout, *, loop=None):
      """Wait for the single Future or coroutine to complete, with timeout.
  
      Coroutine will be wrapped in Task.
  
      Returns result of the Future or coroutine.  When a timeout occurs,
      it cancels the task and raises TimeoutError.  To avoid the task
      cancellation, wrap it in shield().
  
      If the wait is cancelled, the task is also cancelled.
  
      This function is a coroutine.
      """
      if loop is None:
          loop = events.get_event_loop()
  
      if timeout is None:
          return await fut
  
      if timeout <= 0:
          fut = ensure_future(fut, loop=loop)
  
          if fut.done():
              return fut.result()
  
          fut.cancel()
          raise futures.TimeoutError()
  
      waiter = loop.create_future()
      timeout_handle = loop.call_later(timeout, _release_waiter, waiter)
      cb = functools.partial(_release_waiter, waiter)
  
      fut = ensure_future(fut, loop=loop)
      fut.add_done_callback(cb)
  
      try:
          # wait until the future completes or the timeout
          try:
              await waiter
          except futures.CancelledError:
              fut.remove_done_callback(cb)
              fut.cancel()
              raise
  
          if fut.done():
              return fut.result()
          else:
              fut.remove_done_callback(cb)
              # We must ensure that the task is not running
              # after wait_for() returns.
              # See https://bugs.python.org/issue32751
              await _cancel_and_wait(fut, loop=loop)
              raise futures.TimeoutError()
      finally:
          timeout_handle.cancel()
function_tokens: async def wait_for ( fut , timeout , * , loop = None ) : if loop is None : loop = events . get_event_loop ( ) if timeout is None : return await fut if timeout <= 0 : fut = ensure_future ( fut , loop = loop ) if fut . done ( ) : return fut . result ( ) fut . cancel ( ) raise futures . TimeoutError ( ) waiter = loop . create_future ( ) timeout_handle = loop . call_later ( timeout , _release_waiter , waiter ) cb = functools . partial ( _release_waiter , waiter ) fut = ensure_future ( fut , loop = loop ) fut . add_done_callback ( cb ) try : # wait until the future completes or the timeout try : await waiter except futures . CancelledError : fut . remove_done_callback ( cb ) fut . cancel ( ) raise if fut . done ( ) : return fut . result ( ) else : fut . remove_done_callback ( cb ) # We must ensure that the task is not running # after wait_for() returns. # See https://bugs.python.org/issue32751 await _cancel_and_wait ( fut , loop = loop ) raise futures . TimeoutError ( ) finally : timeout_handle . cancel ( )