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

Method wait

tornado/testing.py:295–348  ·  view source on GitHub ↗

Runs the `.IOLoop` until stop is called or timeout has passed. In the event of a timeout, an exception will be thrown. The default timeout is 5 seconds; it may be overridden with a ``timeout`` keyword argument or globally with the ``ASYNC_TEST_TIMEOUT`` environment v

(
        self,
        condition: Optional[Callable[..., bool]] = None,
        timeout: Optional[float] = None,
    )

Source from the content-addressed store, hash-verified

293 self.__stopped = True
294
295 def wait(
296 self,
297 condition: Optional[Callable[..., bool]] = None,
298 timeout: Optional[float] = None,
299 ) -> Any:
300 """Runs the `.IOLoop` until stop is called or timeout has passed.
301
302 In the event of a timeout, an exception will be thrown. The
303 default timeout is 5 seconds; it may be overridden with a
304 ``timeout`` keyword argument or globally with the
305 ``ASYNC_TEST_TIMEOUT`` environment variable.
306
307 If ``condition`` is not ``None``, the `.IOLoop` will be restarted
308 after `stop()` until ``condition()`` returns ``True``.
309
310 .. versionchanged:: 3.1
311 Added the ``ASYNC_TEST_TIMEOUT`` environment variable.
312
313 .. deprecated:: 5.1
314
315 `stop` and `wait` are deprecated; use ``@gen_test`` instead.
316 """
317 if timeout is None:
318 timeout = get_async_test_timeout()
319
320 if not self.__stopped:
321 if timeout:
322
323 def timeout_func() -> None:
324 try:
325 raise self.failureException(
326 "Async operation timed out after %s seconds" % timeout
327 )
328 except Exception:
329 self.__failure = sys.exc_info()
330 self.stop()
331
332 self.__timeout = self.io_loop.add_timeout(
333 self.io_loop.time() + timeout, timeout_func
334 )
335 while True:
336 self.__running = True
337 self.io_loop.start()
338 if self.__failure is not None or condition is None or condition():
339 break
340 if self.__timeout is not None:
341 self.io_loop.remove_timeout(self.__timeout)
342 self.__timeout = None
343 assert self.__stopped
344 self.__stopped = False
345 self.__rethrow()
346 result = self.__stop_args
347 self.__stop_args = None
348 return result
349
350
351class AsyncHTTPTestCase(AsyncTestCase):

Callers 1

tearDownMethod · 0.45

Calls 6

__rethrowMethod · 0.95
get_async_test_timeoutFunction · 0.85
add_timeoutMethod · 0.80
timeMethod · 0.80
startMethod · 0.45
remove_timeoutMethod · 0.45

Tested by

no test coverage detected