Python Forum

Full Version: name a thread defined from a class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi

i have a class using a thread as object

how can i give him a name. it will help the debugging in pycharm

temp.py
class WTemp(threading.Thread):

    def __init__(self, sleep):
        threading.Thread.__init__(self)
        self.sleep = sleep
        self.W_temp = 0

    def run(self):
        while True:
            # reads every sleep interval >0.8 (sensor response minimum delay)
            self.W_temp = W1ThermSensor().get_temperature()
            time.sleep(self.sleep)

    def read_temp(self):
        water_temp = self.W_temp
  
main.py
from temp import Wtemp

Wtemp.start()
how do i give a name to the thread .
in pycharm it appears has Thread7

thanks
no solutions?