Scroll HAT Mini - Flask API

Hey!

I’m new to Python, (coming from a NodeJS background) and I’ve started building a Flask app that allows sending commands to a Pi Zero W with a Scroll Hat Mini in order to trigger cool effects and text scrolling, that get queued up and replayed as subsequent requests are made.

for example, at the moment I can trigger text scrolling based on the route and params passed to the server, e.g. GET /text?text=Arrrr mateys! but am now looking for a light-weight way to queue up the jobs and consume them, something like this (non-working example):

# server.py
import worker 

# start the worker
worker.main()

@app.route('/command/<route>')
def command(route):
    # Store params along with route
    params = request.args 
    # Add the command to a queue
    worker.q.put({ 'command': route, 'params': params })
    # Return and let the user know what was received
    return "command recieved: " + route + " with params: " + str(params.to_dict())

Then in the worker I’ve tried to do something like this:

import Queue
q = Queue.Queue()

def main():
    print('worker running')
    while not q.empty():
        # Do something with the data from the queue
        print(q.get()) 
        print("do a thing - call a function by name?")
 

But this doesn’t work of course, Python is a bit of a new paradigm for me so I’m looking for new ideas!

Any suggestion as to how I can achieve this, or has someone already done this?