Skip to content

Commit

Permalink
Add timeout example
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Oct 14, 2023
1 parent 3f5b0e4 commit 447482d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 13 additions & 0 deletions examples/example_interrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,16 @@ async def interruptor():
await asyncio.sleep(0)
r = await interrupt.create_pytask(interruptor())
assert r == ["ack", "noack"]


async def test_task_timeout():
"""show the interrupt.timeout contextmanager in action"""
with pytest.raises(asyncio.TimeoutError):
async with interrupt.task_timeout(0.1):
try:
await asyncio.sleep(1)
assert False, "should not get here"
except BaseException as e:
# it interrupts us with a base exception
assert isinstance(e, interrupt.TimeoutInterrupt)
raise
1 change: 0 additions & 1 deletion src/asynkit/experimental/interrupt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import asyncio.tasks
import contextlib
import logging
import sys
from asyncio import AbstractEventLoop
from typing import Any, AsyncGenerator, Coroutine, Optional
Expand Down

0 comments on commit 447482d

Please sign in to comment.