MCPcopy Create free account
hub / github.com/EasyIME/PIME / AsyncIOLoop

Class AsyncIOLoop

python/python3/tornado/platform/asyncio.py:307–369  ·  view source on GitHub ↗

``AsyncIOLoop`` is an `.IOLoop` that runs on an ``asyncio`` event loop. This class follows the usual Tornado semantics for creating new ``IOLoops``; these loops are not necessarily related to the ``asyncio`` default event loop. Each ``AsyncIOLoop`` creates a new ``asyncio.EventLoop`

Source from the content-addressed store, hash-verified

305
306
307class AsyncIOLoop(BaseAsyncIOLoop):
308 """``AsyncIOLoop`` is an `.IOLoop` that runs on an ``asyncio`` event loop.
309 This class follows the usual Tornado semantics for creating new
310 ``IOLoops``; these loops are not necessarily related to the
311 ``asyncio`` default event loop.
312
313 Each ``AsyncIOLoop`` creates a new ``asyncio.EventLoop``; this object
314 can be accessed with the ``asyncio_loop`` attribute.
315
316 .. versionchanged:: 6.2
317
318 Support explicit ``asyncio_loop`` argument
319 for specifying the asyncio loop to attach to,
320 rather than always creating a new one with the default policy.
321
322 .. versionchanged:: 5.0
323
324 When an ``AsyncIOLoop`` becomes the current `.IOLoop`, it also sets
325 the current `asyncio` event loop.
326
327 .. deprecated:: 5.0
328
329 Now used automatically when appropriate; it is no longer necessary
330 to refer to this class directly.
331 """
332
333 def initialize(self, **kwargs: Any) -> None: # type: ignore
334 self.is_current = False
335 loop = None
336 if "asyncio_loop" not in kwargs:
337 kwargs["asyncio_loop"] = loop = asyncio.new_event_loop()
338 try:
339 super().initialize(**kwargs)
340 except Exception:
341 # If initialize() does not succeed (taking ownership of the loop),
342 # we have to close it.
343 if loop is not None:
344 loop.close()
345 raise
346
347 def close(self, all_fds: bool = False) -> None:
348 if self.is_current:
349 self._clear_current()
350 super().close(all_fds=all_fds)
351
352 def make_current(self) -> None:
353 warnings.warn(
354 "make_current is deprecated; start the event loop first",
355 DeprecationWarning,
356 stacklevel=2,
357 )
358 if not self.is_current:
359 try:
360 self.old_asyncio = asyncio.get_event_loop()
361 except (RuntimeError, AssertionError):
362 self.old_asyncio = None # type: ignore
363 self.is_current = True
364 asyncio.set_event_loop(self.asyncio_loop)

Callers 3

get_new_ioloopMethod · 0.90
setUpMethod · 0.90

Calls

no outgoing calls

Tested by 3

get_new_ioloopMethod · 0.72
setUpMethod · 0.72