1

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.

Community
  • 1
  • 1
oclaril
  • 33
  • 1
  • 9
  • You can't have a inter process variable easily. They best approach IMHO wold be to have a single threaded micro-service that handles the request to the device and uses some kind of locking and queuing. – Klaus D. May 09 '16 at 09:49
  • This is more or less that I thought before. I thought to create a RabbitMQ server and then use a rpc queues. But I was wondering if it could be achieve with threads or global variables instead of create a new server and so on... – oclaril May 09 '16 at 10:29
  • What's about a fast external storage, such as redis? – Hamlett May 09 '16 at 17:34
  • But this is not good to store objects no? – oclaril May 09 '16 at 18:40

0 Answers0