Feb-21-2019, 12:34 PM
Hi
I'm having a big trouble to get this to work.
I have a function that I want to put in a thread (or multiprocess). This function requires 3 variables.
One of the variables (var_1) is static and no problem passing it through args in the thread module.
The second variable (var_2) changes during the main program
The last variable (flag) i want to use as a trigger when it gets True in the main program.
The "mental" structure of the program should be:
main.py
test.py
But this does not work i think
Someone guru could help me?
I'm having a big trouble to get this to work.
I have a function that I want to put in a thread (or multiprocess). This function requires 3 variables.
One of the variables (var_1) is static and no problem passing it through args in the thread module.
The second variable (var_2) changes during the main program
The last variable (flag) i want to use as a trigger when it gets True in the main program.
The "mental" structure of the program should be:
main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import threading from test import function import time global flag, var_2 var_1 = "var_1" t = threading.Thread(target = function, args = (var_1,)) t.start() while True : var_2 = "var_2 (that changes in each while loop" flag = True time.sleep( 1 ) flag = False |
1 2 3 4 5 6 |
def function(var_1): global var_2, flag while True : if flag = = True : print (var_1 + var_2) |
Someone guru could help me?