Files
hatchet/examples/python/blocked_async/blocking_example_worker.py
Matt Kaye f9d3d508ca Blocked event loop blog post (#1775)
* feat: snippets

* feat: first couple paragraphs

* feat: flesh out hatchet examples

* fix: one more

* feat: log view

* fix: cleanup

* feat: another section

* fix: fmt

* feat: debugging section

* fix: proofread

* fix: lint

* chore: gen

* fix: copilot

* fix: copilot

* feat: add blog post link

* fix: feedback

* chore: sdk ver

* chore: gen

* fix: ugh
2025-05-27 11:07:34 -07:00

44 lines
857 B
Python

# > Worker
import asyncio
import time
from hatchet_sdk import Context, EmptyModel, Hatchet
hatchet = Hatchet()
SLEEP_TIME = 6
@hatchet.task()
async def non_blocking_async(input: EmptyModel, ctx: Context) -> None:
for i in range(SLEEP_TIME):
print("Non blocking async", i)
await asyncio.sleep(1)
@hatchet.task()
def non_blocking_sync(input: EmptyModel, ctx: Context) -> None:
for i in range(SLEEP_TIME):
print("Non blocking sync", i)
time.sleep(1)
@hatchet.task()
async def blocking(input: EmptyModel, ctx: Context) -> None:
for i in range(SLEEP_TIME):
print("Blocking", i)
time.sleep(1)
def main() -> None:
worker = hatchet.worker(
"test-worker", workflows=[non_blocking_async, non_blocking_sync, blocking]
)
worker.start()
if __name__ == "__main__":
main()