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 d86cdd0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 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,13 +296,14 @@ 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 = {}

print("STARLETTE MESSAGE", message, flush=True)
if message.get("type") == "http.disconnect":
self._is_disconnected = True

Expand Down

0 comments on commit d86cdd0

Please sign in to comment.