First of all I have read before all topics about this in stackoverflow like this: Global variable and python flask . I need to have a global object (pyserial object) for doing communication with a device in regular intervals. For doing this, I have used ServerSentEvents. If you use ServerSentEvents, you need to have a async server, for example gunicorn with gevent.
Rightnow I have working ServerSentEvents but the problem is that each request is processed by "random" process, this means, out global variable (pyobject) will be different in each request and this is not good...
How can I have a global unique interprocess variable in flask or in pyton in general?
Thanks in advance.
Edit: One aproach that I follow: Create a RabbitMQ server and then encapsulate pyserial object inside this server. Then I use pika to create a RPC Queue and send the commands to the queue and process it in the RabbitMQ server. In this way I have only one pyserial and I don't have race conditions.