Python global variables?
#1
I've been looking into ways to share data between different scripts and different instances of the same script, and have found that global variables seem to be a reasonable way to achieve this. However, I have a couple of technical questions about this before I go too far into it.

Most pressing, I guess, is their persistence. I understand that XBMC uses a single python instance to run all scripts (hence why the global variables work!) I know no-one has a crystal ball, but is this expected to be the case in the future? Also, will any global variables continue to persist if there are no scripts running, or is the python interpreter shut down in that case?

Also, global variables are often referred to as potentially dangerous in the many Google's I've done on this. Aside from race conditions, which I've already accounted for, is there any particular reason I shouldn't be using these?

Finally, and perhaps more general, whilst global variables are working they're not an ideal solution. Does anyone have any other suggestions for sharing data between scripts? (If it helps, The scripts in their basic form just share a common data file, though they need processing. However - particularly on devices such as the Raspberry Pi - the longest delay is actually in loading the data files, so I'm using globals vars to keep the processed files in memory. I've tried using window properties, but this always increases XBMC's memory usage quite significantly when storing anything more than a simple string, so I'd rather avoid it.)

Thanks in advance!
Reply
#2
Use SQL, it'll be much faster and if your data is structured, it can probably do most of the work for you.
Reply
#3
SQL is a superb suggestion, thanks!
Reply

Logout Mark Read Team Forum Stats Members Help
Python global variables?0