I'm creating a communication program to make a raspberry send me information to the computer. This information will need to be manipulated by other threads. So, in the main thread, I'm actually initializing the server and so on, and manipulating the variable, and in the secondary thread, I'm manipulating the data.
The code I'm using is the following:
import sys # Necessaty to insert the path of files that are in other folders
from communication_class import Server
import pickle
import threading
import time
sys.path.append('/home/pablo/Desktop/MY_THESIS/MasterThesisFiles_AR/measurement_processing/')
import filtering
computer = Server() # Needs to be initialized before-hand so it can be used in the
computer.ChangePort(5020)
def DataEvaluation(n_var, n_states):
print("Inside Data Evaluation")
while True:
print(computer.data)
#time.sleep(1)
data_thread = threading.Thread(target = DataEvaluation, args = (9, 5))
computer.create_socket()
computer.create_server()
computer.start(computer.handle_readings)
The problem is that the data_thread isn't doing what it says, or at least it doesn't print any information (this is, the print(computer.data)
and the print("Inside Data Evaluation")
don't appear to be executed). Are they being executed, but because they are in other threads, they don't appear, or what is going on?
question from:
https://stackoverflow.com/questions/66066404/accesing-variables-in-a-thread-that-are-being-modified-in-the-main-program 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…