Python shared queue - 2 different threads Python shared queue - 2 different threads flask flask

Python shared queue - 2 different threads


When you create a new process, it copies the current environment and re-creates it in the new environment. Once you create the process, those global variables are no longer shared.

However, the multiprocessing library has included ways to communicate between processes

You can still use a queue, but you'll have to use the multiprocessing Queue instead of your home-rolled one. Under the hood, each process has its own Queue object, and they're simply piping information back and forth between the processes to sync the queue state.