Return a `.Future` that resolves after the given number of seconds. When used with ``yield`` in a coroutine, this is a non-blocking analogue to `time.sleep` (which should not be used in coroutines because it is blocking):: yield gen.sleep(0.5) Note that calling this functi
(duration: float)
| 655 | |
| 656 | |
| 657 | def sleep(duration: float) -> "Future[None]": |
| 658 | """Return a `.Future` that resolves after the given number of seconds. |
| 659 | |
| 660 | When used with ``yield`` in a coroutine, this is a non-blocking |
| 661 | analogue to `time.sleep` (which should not be used in coroutines |
| 662 | because it is blocking):: |
| 663 | |
| 664 | yield gen.sleep(0.5) |
| 665 | |
| 666 | Note that calling this function on its own does nothing; you must |
| 667 | wait on the `.Future` it returns (usually by yielding it). |
| 668 | |
| 669 | .. versionadded:: 4.1 |
| 670 | """ |
| 671 | f = _create_future() |
| 672 | IOLoop.current().call_later( |
| 673 | duration, lambda: future_set_result_unless_cancelled(f, None) |
| 674 | ) |
| 675 | return f |
| 676 | |
| 677 | |
| 678 | class _NullFuture(object): |
nothing calls this directly
no test coverage detected