Hi Antonis,
On 2018-01-09 07:14, Antonis Christofides wrote:
> Ah, OK, sorry I didn't read all the discussion. So I guess that if you keep that
> in a global variable, it won't work if your Django app is running in many
> processes. (Besides, global variables are rarely a good idea.)
>
I agree completely that global variables should be avoided. I find them
to be even more problematic in a language like python where they could
be instatiated by simply importing a file/module. That's probably OK for
a simple value like an integer, but I prefer imports not to have too
many side effects.
> If I understand the problem correctly, what I would do would probably be to
> touch a file whenever I make a change and examine the file modification date
> each time—if it's more recent than last time I checked, the data has been modified.
>
> Another option is to use the cache. For example, use memcached and store some
> data in there. IIRC the cache is shared among all instances of Django.
>
That's not really solving my problem, but thanks for your input. What I
need is a "global" python popen object from the subprocess module.
Someone helpfully suggested using a singleton for that. I really don't
like singletons either, but this could actually be one of the few use
cases where that would make sense, so I think that's what I'll be doing.
Kind regards,
Kasper Laudrup