When it comes to threading, I know you have to make sure you’re not editing a variable at the same time another thread is editing it, as your changes can be lost (when incrementing a counter, for example)
Does the same apply to dictionaries? Or is a dictionary a collection of variables?
If every thread were to lock the dictionary it would slow the program down significantly, while every thread only needs write access to its own little piece of the dictionary.
If it isn’t possible, is there some sort of variable variable in python, like in php?
I think you misundertood this whole thread safety thing. It’s not so much about variables (or variable variables – those are terrible anyway, and are just as pointless – not to say harmful – here as in every other case) but about — for example, there are many nasty nasty ways threading can go wrong; they all come from accessing something mutable from more than one thread at overlapping times — this:
And it applies to dictionaries and variable variables (which are just a horrible, horrible language-level implementation of dicts with string-only keys) as well. The only solutions are not using shared state to begin with (functional languages do this by discouraging or even completely disallowing mutability, and it works well for them) or adding some sort of locking to everything shared (hard to get right, but if you get it right, at least it works correctly). If no two threads every share anything in that dictionary, you’re fine – but you should seperate everything, to be (a bit more) sure that they really don’t share anything.