Right now I have the following structure in my code. The request is directly parsed as JSON.
while True:
if self.rest_sock.poll(timeout=0):
request = self.rest_sock.recv_json()
...
I want to replace the loop with an asynchronous call of a function (to reduce CPU time as explained here: https://stackoverflow.com/a/21937311/10555800). This is done by registering a function as an event handler by using on_recv()
. But the JSON message is not parsed. I assume I could parse it myself as explained e.g. here https://stackoverflow.com/a/34242555/10555800. But I was wondering why there nothing equivalent to socket.recv_json()
for an async receive of json messages like on_recv_json()
.
Edit (Answering Questions from @bazza):
None
.What else is going on in the code?
recv()
, which will block until a message turns up. Polling in that case is not necessary.It's helpful to know a dictionary definition of "poll" as meaning "check on the status of".