agronholm / agronholm/anyio

`fail_after` deadline is set on initialization not context entry

Đang mở
#514 8 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
2.5k
Fork
260
Merge trung bình
2 ngày 8 giờ
Pull request đã merge (30 ngày)
19

Mô tả

Discussed at https://gitter.im/python-trio/AnyIO?at=63ac6d617de82d261600ea24

When using a `fail_after` context, the deadline is set at "initialization" time rather than `__enter__`. See https://github.com/agronholm/anyio/blob/0cbb84bfadd9078c5dad63bab43907ed0dd555a1/src/anyio/_core/_tasks.py#L112-L114

```python
import anyio

async def main():
ctx = anyio.fail_after(5)
await anyio.sleep(5)
with ctx:
for i in range(1, 6):
print(i)
await anyio.sleep(1)

anyio.run(main)
```
```
❯ python example.py
1
Traceback (most recent call last):
File "/Users/mz/dev/prefect/example.py", line 168, in main
await anyio.sleep(1)
File "/opt/homebrew/Caskroom/miniconda/base/envs/orion-dev-39/lib/python3.9/site-packages/anyio/_core/_eventloop.py", line 83, in sleep
return await get_asynclib().sleep(delay)
File "/opt/homebrew/Caskroom/miniconda/base/envs/orion-dev-39/lib/python3.9/asyncio/tasks.py", line 652, in sleep
return await future
asyncio.exceptions.CancelledError
```

Since this is a context manager, the user expectation is that the timer starts when the context is entered.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.