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

Method initialize

python/python3/tornado/platform/asyncio.py:93–140  ·  view source on GitHub ↗
(  # type: ignore
        self, asyncio_loop: asyncio.AbstractEventLoop, **kwargs: Any
    )

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

copyMethod · 0.80
initializeMethod · 0.45

Tested by

no test coverage detected