Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 41
Asyncio
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))Contributions are appreciated – simply hit Edit or New page.