Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

python - Accesing variables in a thread that are being modified in the main program

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...