I have my raspberry pi running flask/Apache. I have a background task that I run using multiprocessing. (I know celery does this, but I just wanted something simple).
My issue is that the background process runs twice. It start once when a single web page is opened, the again when the second is opened. Funny thing, it doesn't run a third time if a third web page is open.
Question: How can I troubleshoot why this is happening, and how might I prevent it?
@app.before_first_request def start_background(): global p p = Process(target=main_loop) p.start()
Currently, I solve it by doing the following -- but that seems hokey
@app.before_first_request def start_background(): stop_background() time.sleep(0.5) global p p = Process(target=main_loop) p.start()