I am trying to create a Python producer and consumer using 2 asynchronous functions. 1 of the functions is a callback getting data from server (producer), the other is a timed callback that executes every N seconds (consumer). I am trying to use ZMQ/Reactor for this as I would like to avoid overhead of a timer thread and just use the event loop. Does the ZMQ/Reactor event loop execute each event in order they arrive or is there a chance that the consumer function could be context switched to the producer function at any time?
Simplified Example:
The main issue is that I cannot pop all items from a list and clear it atomically
queue = []
def producer():
# gets data from server
queue.append(single_record)
def consumer():
records = list(queue)
# inserts records into db
queue.clear()