MCPcopy Create free account
hub / github.com/Louisym/MiniCC / demo_timeout

Function demo_timeout

tutorials/17_async_await_for_sse.py:257–266  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

255 return "完成"
256
257 async def demo_timeout():
258 # 给慢操作设置 0.5 秒超时
259 try:
260 result = await asyncio.wait_for(
261 slow_operation(),
262 timeout=0.5,
263 )
264 print(f" 成功: {result}")
265 except asyncio.TimeoutError:
266 print(f" 超时! 操作在 0.5s 后被取消")
267
268 print("\n 等待一个 10s 的操作,但超时设为 0.5s:")
269 asyncio.run(demo_timeout())

Callers 1

lesson_4_timeoutFunction · 0.85

Calls 1

slow_operationFunction · 0.85

Tested by

no test coverage detected