I am currently having issues to do with my understanding of threading or possibly my understanding of how variables are passed/assigned thru threads in python. I have this simple program that takes in a list of current stocks that are displayed on a screen and grabs the stock information related to those. I am using threads so that I can constantly update the screen and constantly collect data. I am having two issues:
- Inside
dataCollector_thread()
i understand that if i append to thestocksOnScreenListInfo
that the variable (stocksOnScreenListInfo
) insidemain
is updated.
However I don't want to append to the list but rather just reassign the list like the following but this does not work?.
def dataCollector_thread(stocksOnScreenListInfo, stocksOnScreen):
while(True):
placeholder = []
for stock in stocksOnScreen:
placeholer.append(RetrieveQuote(stock))
stocksOnScreenListInfo = placeholder
time.sleep(5)
Inside
screenUpdate_thread
i am wanting to updatestocksOnScreen
to the variable 'TSLA' defined by the functionUpdateScreen
. This does not seem to update its correspondingstocksOnScreen
inmain
as when I print to check it continues to say 'AAPL'?def main(args): stocksOnScreen = ["AAPL"] # List of the stocks currently displayed on LED screen stocksOnScreenListInfo = [] # The quote information list for each stock on screen thread_data_collector = threading.Thread(target=dataCollector_thread, args=(stocksOnScreenListInfo,stocksOnScreen)) thread_data_collector.daemon = True thread_data_collector.start() thread_screen = threading.Thread(target=screenUpdate_thread, args=(stocksSearchArray,stocksOnScreen)) thread_screen.daemon = True thread_screen.start() def dataCollector_thread(stocksOnScreenListInfo, stocksOnScreen): while(True): for stock in stocksOnScreen: stocksOnScreenListInfo.append(RetrieveQuote(stock)) time.sleep(5) def screenUpdate_thread(stocksSearchArray, stocksOnScreen): while(True): stocksOnScreen = UpdateScreen(stocksSearchArray) def UpdateScreen(stocksSearchArray): pass return ["TSLA"]