Skip to content

Commit a51cd72

Browse files
committed
Merge the atomesh client (#3675) into discovery and P/D
2 parents 4e11242 + b401205 commit a51cd72

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎atom/entrypoints/grpc/server.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,13 @@ def start_grpc_server(api: ModuleType, args: Namespace) -> Callable[[], None]:
456456
target=_run, args=(address, servicer, listening), name=THREAD_NAME, daemon=True
457457
)
458458
thread.start()
459-
loop, server = listening.result()
459+
loop, stopping = listening.result()
460460

461461
def stop() -> None:
462462
"""Refuses new calls and ends the running ones, their seqs aborted; run before
463463
the engine closes, which would leave them waiting forever."""
464-
asyncio.run_coroutine_threadsafe(server.stop(None), loop).result()
465-
thread.join() # stop returns before the calls' teardown has run
464+
loop.call_soon_threadsafe(stopping.set)
465+
thread.join() # server.stop returns before the calls' teardown has run
466466

467467
return stop
468468

@@ -484,5 +484,8 @@ async def _serve(address: str, servicer: AtomEngineServicer, listening: Future)
484484
except Exception as error: # noqa: BLE001 - start_grpc_server raises it
485485
listening.set_exception(error)
486486
return
487-
listening.set_result((asyncio.get_running_loop(), server))
488-
await server.wait_for_termination()
487+
stopping = asyncio.Event()
488+
listening.set_result((asyncio.get_running_loop(), stopping))
489+
await stopping.wait()
490+
# Stopped here, not from another task: asyncio.run would cancel that one.
491+
await server.stop(None)

‎tests/test_grpc_server.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,18 @@ def test_prepare_refuses_what_the_chat_route_refuses_with_a_400(chat, fields, me
372372
assert engine.grammars == []
373373

374374

375+
def test_generate_refuses_stops_with_a_response_schema_as_the_chat_route_does(chat):
376+
engine = FakeEngine()
377+
structured = pb.StructuredOutput(response_format_json=RESPONSE_FORMAT)
378+
stops = [v1.TokenIds(ids=[7])]
379+
written = _generate(
380+
chat(engine), structured_output=structured, stop_token_sequences=stops
381+
)
382+
error = _error(written)
383+
assert error.http_status == 400 and "custom stop strings" in error.message
384+
assert engine.grammars == [] and engine.preprocessed == []
385+
386+
375387
def test_chat_template_kwargs_must_be_an_object(chat):
376388
structured = pb.StructuredOutput(chat_template_kwargs_json="[]")
377389
error = _prepare(chat(FakeEngine()), structured).error

0 commit comments

Comments
 (0)