-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Propagate Client Disconnect through Truss (#1118)
* Wire up client disconnect - not working in test * Works for streaming with cURL. Test doesnt work and JSON doesnt work. * Streaming test does work now. * Make passing of is_cancelled_fn depdendent on function signature
- Loading branch information
1 parent
333a0e6
commit 01192bd
Showing
7 changed files
with
95 additions
and
12 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
4 changes: 4 additions & 0 deletions
4
truss/test_data/test_streaming_async_cancellable_generator_truss/config.yaml
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,4 @@ | ||
model_name: Test Streaming Async Generator | ||
python_version: py39 | ||
environment_variables: | ||
OTEL_TRACING_NDJSON_FILE: "/tmp/otel_traces.ndjson" |
31 changes: 31 additions & 0 deletions
31
truss/test_data/test_streaming_async_cancellable_generator_truss/model/model.py
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,31 @@ | ||
import asyncio | ||
from typing import Any, Awaitable, Callable, Dict, List | ||
|
||
|
||
class Model: | ||
def __init__(self, **kwargs) -> None: | ||
self._data_dir = kwargs["data_dir"] | ||
self._config = kwargs["config"] | ||
self._secrets = kwargs["secrets"] | ||
self._model = None | ||
|
||
def load(self): | ||
# Load model here and assign to self._model. | ||
pass | ||
|
||
async def predict( | ||
self, model_input: Any, is_cancelled_fn: Callable[[], Awaitable[bool]] | ||
) -> Dict[str, List]: | ||
# Invoke model on model_input and calculate predictions here. | ||
await asyncio.sleep(1) | ||
if await is_cancelled_fn(): | ||
print("Cancelled (before gen).") | ||
return | ||
|
||
for i in range(5): | ||
await asyncio.sleep(1.0) | ||
print(i) | ||
yield str(i) | ||
if await is_cancelled_fn(): | ||
print("Cancelled (during gen).") | ||
return |
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