I’m trying to get the following global variable storage_i to be accessible to the lvl1 function, I have been able to pass it to other functions inside of the class birdofprey but I can’t get it outside of that framework. I have looked around at using global variables between functions, etc, and I have also seen global var usage discouraged. But, basically I am trying to have the value of storage_i summed up from all the threads. So if that could be done without a global variable that would also be great. Any help would be appreciated.
The Code: https://github.com/eWizardII/homobabel/blob/master/Experimental/demo_async_falcon.py
Replace this:
With this:
You also have a typo at line 75:
(
stroage_iwas intended to bestorage_i)This line should actually be:
EDIT: Also, without having looked closely at it, your use of a class attribute (storage_i) looks like it’s susceptible to race conditions. Consider using mutexes to guard accesses to that attribute. I think you also need to wait for the threads to finish executing before you can access the values.
But I’m not sure if a global (or class attribute) is really what you want. I think what you really want is a thread-local variable that you can access after the thread has finished (see the
Thread.joinmethod.) If I’m reading that correctly, then forget what I wrote above about mutexes. Instead, set the storage_i attribute asself.storage_i(creating a separate instance for each thread.) Then in theforloop where you’re summing the values, access the value asurlv.storage_i. Again, it looks like it’s important that you perform ajoinon each thread before you try to access its values.That’s all the help I can offer for now; perhaps tomorrow morning (my time) I can check in again.