Files
hatchet/examples/python/blocked_loop_blog/snippets.py
matt 93454d6e75 Fix: More doc snippets (#2267)
* fix: batch i

* fix: batch ii

* fix: batch iii

* fix: batch iv

* fix: batch v

* fix: guide

* fix: batch vi

* fix: batch vii

* fix: dag docs

* fix: separate dag tasks
2025-09-09 15:37:20 -04:00

41 lines
480 B
Python

import asyncio
import time
# > Async-safe
async def async_safe() -> int:
await asyncio.sleep(5)
return 42
# > Blocking
async def blocking() -> int:
time.sleep(5)
return 42
# > Using to_thread
async def to_thread() -> int:
await asyncio.to_thread(time.sleep, 5)
return 42
# > Using run_in_executor
async def run_in_executor() -> int:
loop = asyncio.get_event_loop()
await loop.run_in_executor(None, time.sleep, 5)
return 42