Skip to content

Commit

Permalink
WIP revert to asyncio for .is_disconnected()
Browse files Browse the repository at this point in the history
Fixes: 42592d6 ("anyio integration (encode#1157)")
  • Loading branch information
gctucker committed Jun 12, 2024
1 parent 554f368 commit 8577d41
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions starlette/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import json
import typing
from http import cookies as http_cookies
Expand Down Expand Up @@ -295,12 +296,12 @@ async def close(self) -> None:

async def is_disconnected(self) -> bool:
if not self._is_disconnected:
message: Message = {}

# If message isn't immediately available, move on
with anyio.CancelScope() as cs:
cs.cancel()
message = await self._receive()
try:
message = await asyncio.wait_for(
self._receive(), timeout=0.0000001
)
except asyncio.TimeoutError:
message = {}

if message.get("type") == "http.disconnect":
self._is_disconnected = True
Expand Down

0 comments on commit 8577d41

Please sign in to comment.