MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / callback_coro

Method callback_coro

pywebio/session/coroutinebased.py:182–209  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

180 """
181
182 async def callback_coro():
183 while True:
184 try:
185 event = await self.next_client_event()
186 except SessionClosedException:
187 return
188
189 assert event['event'] == 'callback'
190 coro = None
191 if iscoroutinefunction(callback):
192 coro = callback(event['data'])
193 elif isgeneratorfunction(callback):
194 coro = asyncio.coroutine(callback)(event['data'])
195 else:
196 try:
197 res = callback(event['data'])
198 if asyncio.iscoroutine(res):
199 coro = res
200 else:
201 del res # `res` maybe pywebio.io_ctrl.Output, so need release `res`
202 except Exception:
203 self.on_task_exception()
204
205 if coro is not None:
206 if mutex_mode:
207 await coro
208 else:
209 self.run_async(coro)
210
211 cls = type(self)
212 callback_task = Task(callback_coro(), cls.get_current_session())

Callers

nothing calls this directly

Calls 6

next_client_eventMethod · 0.95
run_asyncMethod · 0.95
iscoroutinefunctionFunction · 0.85
isgeneratorfunctionFunction · 0.85
on_task_exceptionMethod · 0.80
callbackFunction · 0.50

Tested by

no test coverage detected