( # type: ignore
self, asyncio_loop: asyncio.AbstractEventLoop, **kwargs: Any
)
| 93 | |
| 94 | class BaseAsyncIOLoop(IOLoop): |
| 95 | def initialize( # type: ignore |
| 96 | self, asyncio_loop: asyncio.AbstractEventLoop, **kwargs: Any |
| 97 | ) -> None: |
| 98 | # asyncio_loop is always the real underlying IOLoop. This is used in |
| 99 | # ioloop.py to maintain the asyncio-to-ioloop mappings. |
| 100 | self.asyncio_loop = asyncio_loop |
| 101 | # selector_loop is an event loop that implements the add_reader family of |
| 102 | # methods. Usually the same as asyncio_loop but differs on platforms such |
| 103 | # as windows where the default event loop does not implement these methods. |
| 104 | self.selector_loop = asyncio_loop |
| 105 | if hasattr(asyncio, "ProactorEventLoop") and isinstance( |
| 106 | asyncio_loop, asyncio.ProactorEventLoop |
| 107 | ): |
| 108 | # Ignore this line for mypy because the abstract method checker |
| 109 | # doesn't understand dynamic proxies. |
| 110 | self.selector_loop = AddThreadSelectorEventLoop(asyncio_loop) # type: ignore |
| 111 | # Maps fd to (fileobj, handler function) pair (as in IOLoop.add_handler) |
| 112 | self.handlers: Dict[int, Tuple[Union[int, _Selectable], Callable]] = {} |
| 113 | # Set of fds listening for reads/writes |
| 114 | self.readers: Set[int] = set() |
| 115 | self.writers: Set[int] = set() |
| 116 | self.closing = False |
| 117 | # If an asyncio loop was closed through an asyncio interface |
| 118 | # instead of IOLoop.close(), we'd never hear about it and may |
| 119 | # have left a dangling reference in our map. In case an |
| 120 | # application (or, more likely, a test suite) creates and |
| 121 | # destroys a lot of event loops in this way, check here to |
| 122 | # ensure that we don't have a lot of dead loops building up in |
| 123 | # the map. |
| 124 | # |
| 125 | # TODO(bdarnell): consider making self.asyncio_loop a weakref |
| 126 | # for AsyncIOMainLoop and make _ioloop_for_asyncio a |
| 127 | # WeakKeyDictionary. |
| 128 | for loop in IOLoop._ioloop_for_asyncio.copy(): |
| 129 | if loop.is_closed(): |
| 130 | try: |
| 131 | del IOLoop._ioloop_for_asyncio[loop] |
| 132 | except KeyError: |
| 133 | pass |
| 134 | |
| 135 | # Make sure we don't already have an IOLoop for this asyncio loop |
| 136 | existing_loop = IOLoop._ioloop_for_asyncio.setdefault(asyncio_loop, self) |
| 137 | if existing_loop is not self: |
| 138 | raise RuntimeError( |
| 139 | f"IOLoop {existing_loop} already associated with asyncio loop {asyncio_loop}" |
| 140 | ) |
| 141 | |
| 142 | super().initialize(**kwargs) |
| 143 | |
| 144 | def close(self, all_fds: bool = False) -> None: |
| 145 | self.closing = True |
nothing calls this directly
no test coverage detected