Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: generalize helper function for streaming simulation #1769

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/phoenix/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from random import random
from threading import Thread
from time import sleep, time
from typing import Iterable, Optional
from typing import Iterable, Optional, Protocol, TypeVar

from uvicorn import Config, Server

Expand All @@ -27,7 +27,6 @@
_download_traces_fixture,
_get_trace_fixture_by_name,
)
from phoenix.trace.schemas import Span
from phoenix.trace.span_json_decoder import json_string_to_span

logger = logging.getLogger(__name__)
Expand All @@ -54,15 +53,23 @@ def _get_pid_file() -> Path:
return get_pids_path() / str(os.getpid())


def _load_spans(
traces: Traces,
spans: Iterable[Span],
_Item = TypeVar("_Item", contravariant=True)


class _SupportsPut(Protocol[_Item]):
def put(self, item: _Item) -> None:
...


def _load_items(
queue: _SupportsPut[_Item],
items: Iterable[_Item],
simulate_streaming: Optional[bool] = False,
) -> None:
for span in spans:
for item in items:
if simulate_streaming:
sleep(random())
traces.put(span)
queue.put(item)


DEFAULT_UMAP_PARAMS_STR = f"{DEFAULT_MIN_DIST},{DEFAULT_N_NEIGHBORS},{DEFAULT_N_SAMPLES}"
Expand Down Expand Up @@ -146,7 +153,7 @@ def _load_spans(
),
)
Thread(
target=_load_spans,
target=_load_items,
args=(traces, fixture_spans, simulate_streaming),
daemon=True,
).start()
Expand Down
Loading