danielgtaylor / danielgtaylor/python-betterproto

Documentation errors

Aperta
#208 1 commento 3 reazioni 0 assegnatari Vedi su GitHub
documentation
Lingua principale
Python
Stelle
1.8k
Fork
234
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

There're a few issues with the example server, even after using the prerelease version. Probably not worth a PR, so here's an update example with notes below:

```python
import asyncio

from echo import EchoBase, EchoResponse, EchoStreamResponse
from grpclib.server import Server
from typing import AsyncIterator

class EchoService(EchoBase):
async def echo(self, value: str, extra_times: int) -> EchoResponse:
return EchoResponse(values=[value] * extra_times)

async def echo_stream(
self, value: str, extra_times: int
) -> AsyncIterator[EchoStreamResponse]:
for _ in range(extra_times):
yield EchoStreamResponse(value=value)

async def start_server():
HOST = "127.0.0.1"
PORT = 50051
server = Server([EchoService()])
await server.start(HOST, PORT)
await server.wait_closed()

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(start_server())
loop.close()

```

### Changes

- Added imports of `EchoReponse` and `EchoStreamResponse`
- Updated `echo` and `echo_stream` to return the correct types
- Updated `PORT` to match that in the client example
- Replaced `await server.run_forever()` (raises a `NotImplementedError`) with `await server.wait_closed()`
- Added an asyncio loop at the bottom to actually run the server

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.