1

I have some async websocket code that runs forever and gives me data on a zmq socket. On my "receiver" page, I have this code:

while True:
    msg = zmqsocket.signal_recv()
    new_msg = data_preparation_function(msg)
    other_function(new_msg)

My data preparation function aggregates this data, and once every x messages yields an aggregated message that the other functions use do things.

My question is, should I rewrite the data_preparation_function using asyncio if the other_functions can't do anything if the first function hasn't finished running?

Since the zmq socket yields thousands of messages per second, and the other_functions take some time to run, I'm afraid of loosing data while the functions are running if I don't read it from the socket, hence I was considering doing everything async.

I'm using Python 3.7.7

Rbdm
  • 39
  • 4
  • once every x messages, you mean ```other_function``` need to be called when ```data_prepartaion_function(msg)``` yields? Seems like current code is calling on every message receive, blocking ```signal_recv()``` – jupiterbjy Aug 22 '20 at 01:32

0 Answers0