mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-18 14:49:45 -06:00
* 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
41 lines
480 B
Python
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
|
|
|
|
|