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):
- There is something else for my program to do in the meantime. This did lead to some other issues and I have already fixed this by setting the timeout to
None
. - I assume I could also remove the poll as you suggested as everything related to the socket connection is running in its own thread and therefore should not block the complete program