-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1735 from langchain-ai/nc/16sep/stream-subgraph-i…
…n-progress Stream subgraph output while it executes
- Loading branch information
Showing
6 changed files
with
162 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import asyncio | ||
import sys | ||
|
||
PY_310 = sys.version_info >= (3, 10) | ||
|
||
|
||
class Queue(asyncio.Queue): | ||
async def wait(self): | ||
"""If queue is empty, wait until an item is available. | ||
Copied from Queue.get(), removing the call to .get_nowait(), | ||
ie. this doesn't consume the item, just waits for it. | ||
""" | ||
while self.empty(): | ||
if PY_310: | ||
getter = self._get_loop().create_future() | ||
else: | ||
getter = self._loop.create_future() | ||
self._getters.append(getter) | ||
try: | ||
await getter | ||
except: | ||
getter.cancel() # Just in case getter is not done yet. | ||
try: | ||
# Clean self._getters from canceled getters. | ||
self._getters.remove(getter) | ||
except ValueError: | ||
# The getter could be removed from self._getters by a | ||
# previous put_nowait call. | ||
pass | ||
if not self.empty() and not getter.cancelled(): | ||
# We were woken up by put_nowait(), but can't take | ||
# the call. Wake up the next in line. | ||
self._wakeup_next(self._getters) | ||
raise |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters