multithreading - python - update thread variable -
how update variable inside running thread, infinite loop based on such variable?
simplified version of tried follows, no results of course, , can't find pointer.
import some_module mod import threading class thr (threading.thread): num = 5 # set default value start script def run (self): mod.num = num mod.main_loop() try: thr().start() time.sleep(1) thr().num = 2 time.sleep(1) thr().num = 6 time.sleep(1) thr().num = 8
the problem you're creating new thread each time "call" (i.e. instantiate) thr
. change code to
t = thr() t.start() time.sleep(1) t.num = 2 time.sleep(1) t.num = 6 time.sleep(1) t.num = 8 time.sleep(1)