MCPcopy
hub / github.com/tornadoweb/tornado / add_timeout

Method add_timeout

tornado/ioloop.py:563–602  ·  view source on GitHub ↗

Runs the ``callback`` at the time ``deadline`` from the I/O loop. Returns an opaque handle that may be passed to `remove_timeout` to cancel. ``deadline`` may be a number denoting a time (on the same scale as `IOLoop.time`, normally `time.time`), or a `dateti

(
        self,
        deadline: Union[float, datetime.timedelta],
        callback: Callable,
        *args: Any,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

561 return time.time()
562
563 def add_timeout(
564 self,
565 deadline: Union[float, datetime.timedelta],
566 callback: Callable,
567 *args: Any,
568 **kwargs: Any,
569 ) -> object:
570 """Runs the ``callback`` at the time ``deadline`` from the I/O loop.
571
572 Returns an opaque handle that may be passed to
573 `remove_timeout` to cancel.
574
575 ``deadline`` may be a number denoting a time (on the same
576 scale as `IOLoop.time`, normally `time.time`), or a
577 `datetime.timedelta` object for a deadline relative to the
578 current time. Since Tornado 4.0, `call_later` is a more
579 convenient alternative for the relative case since it does not
580 require a timedelta object.
581
582 Note that it is not safe to call `add_timeout` from other threads.
583 Instead, you must use `add_callback` to transfer control to the
584 `IOLoop`'s thread, and then call `add_timeout` from there.
585
586 Subclasses of IOLoop must implement either `add_timeout` or
587 `call_at`; the default implementations of each will call
588 the other. `call_at` is usually easier to implement, but
589 subclasses that wish to maintain compatibility with Tornado
590 versions prior to 4.0 must use `add_timeout` instead.
591
592 .. versionchanged:: 4.0
593 Now passes through ``*args`` and ``**kwargs`` to the callback.
594 """
595 if isinstance(deadline, numbers.Real):
596 return self.call_at(deadline, callback, *args, **kwargs)
597 elif isinstance(deadline, datetime.timedelta):
598 return self.call_at(
599 self.time() + deadline.total_seconds(), callback, *args, **kwargs
600 )
601 else:
602 raise TypeError("Unsupported deadline %r" % deadline)
603
604 def call_later(
605 self, delay: float, callback: Callable, *args: Any, **kwargs: Any

Callers 15

run_syncMethod · 0.95
call_atMethod · 0.95
set_timeoutMethod · 0.80
set_connect_timeoutMethod · 0.80
with_timeoutFunction · 0.80
waitMethod · 0.80
_set_timeoutFunction · 0.80
_set_timeoutMethod · 0.80
waitMethod · 0.80
acquireMethod · 0.80
_schedule_nextMethod · 0.80
fetch_implMethod · 0.80

Calls 2

call_atMethod · 0.95
timeMethod · 0.95

Tested by 15

waitMethod · 0.64
test_wait_timeoutMethod · 0.64
test_event_timeoutMethod · 0.64
test_empty_requestMethod · 0.64
tearDownMethod · 0.64