'Updating and refering to a global list
I'm working on a script in python and I'm having some trouble with something. I'm trying to have a global list that some defined functions refer and append to. These functions are recursive and run in parallel using multiprocessing, some updating the list with live data, and then others grabbing that data to be used in other calculations. However, for some reason, only the local list inside the updating function seems to get updated while the global list remains empty. Here's an oversimplified example of the operation I'm trying to do:
log = []
avGradLog = []
def UpdateLog():
data = get_data
log.append(data)
time.sleep(dt)
UpdateLog()
def ReferToLog():
m = gradient(log[chosen_point], log[chosen_point2]) #defined elsewhere
avGradLog.append(m)
time.sleep(dt)
ReferToLog()
Please keep in mind I am from a Theoretical Physics background so my CS knowledge is very much lacking and couldn't find much online so my apologies if this is a very elementary question.
Thank you in advance, Tony.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
