Skip to content
Beau Barker edited this page Jul 3, 2025 · 3 revisions

Asyncio server, demonstrating the processing of a batch of 100 requests asynchronously with asyncio.

importasyncioimportjsonfromjsonrpcserverimportResult, Success, async_dispatch, method@methodasyncdefsleep_() ->Result:
"""JSON-RPC method"""awaitasyncio.sleep(1)
returnSuccess()
asyncdefhandle(req: str) ->None:
"""Handle asyncio event"""print(awaitasync_dispatch(req))
if__name__=="__main__":
request=json.dumps(
[{"jsonrpc": "2.0", "method": "sleep_", "id": 1} for_inrange(100)]
)
asyncio.get_event_loop().run_until_complete(handle(request))

Clone this wiki locally