I'm working on a thread that updates a variable of the main process. As I did not succeed passing arguments I had to use global. But I don't like it, it's not safe. There is any way without using global?
I can pass the argument, but my issue is with the returning object.
My code:
#!usr/bin/python3
# -*- coding: UTF-8 -*-
import threading
import time
my_check = " CHECK " # TODO replace with initial source data.
class MiThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
time.sleep(5)
print("I'm the SECOND thread")
global my_check
my_check = " CHECK DONE!!!" # TODO replace with the updated source data.
self.run()
print ("I'm the principal thread.")
t = MiThread()
t.start()
#t.join(1)
while True:
time.sleep(0.5)
print("I'm the principal thread, too." + my_check)
This is only a concept proof, really I want to code a little stocks ticker displayer in a tkinter label, and I need, at least two more threads: the updater thread (for update the information to display) and the displayer thread (it must changes the text of the label each 0.3 seconds).