mirror of
https://github.com/langgenius/dify.git
synced 2026-02-01 16:41:58 +08:00
feat: improve read behavior in QueueTransportReadCloser to handle initial data wait and subsequent immediate returns
This commit is contained in:
parent
926349b1f8
commit
a911b268aa
@ -74,7 +74,11 @@ class QueueTransportReadCloser(TransportReadCloser):
|
||||
|
||||
to_return = self._drain_buffer(n)
|
||||
|
||||
while len(to_return) < n and not self._closed and self.q.qsize() > 0:
|
||||
# At the first round reading from queue, hanging is required to wait for the data
|
||||
# But after that, return immediately if no data is available
|
||||
round = 0
|
||||
|
||||
while len(to_return) < n and not self._closed and (self.q.qsize() > 0 or round == 0):
|
||||
chunk = self.q.get()
|
||||
if chunk is None:
|
||||
self._closed = True
|
||||
@ -92,6 +96,8 @@ class QueueTransportReadCloser(TransportReadCloser):
|
||||
# No more data needed, break
|
||||
break
|
||||
|
||||
round += 1
|
||||
|
||||
return to_return
|
||||
|
||||
def _drain_buffer(self, n: int) -> bytes:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user