I have a program running on several threads and I'm trying to change a variable self.pausing
, through the telegram api, while the program is running. I made a function that changes the variable upon receiving a message:
from time import sleep
import threading
class program:
def __init__(self):
self.pausing = False
def paus(self):
if self.pausing == False:
self.pausing = True
print('self.pausing = True')
elif self.pausing == True:
self.pausing = False
print('self.pausing = False')
def run(self):
while True:
if self.pausing == False:
sleep(2)
print(self.pausing)
sleep(2)
print('Doing things...')
elif self.pausing == True:
print('Pausing..')
sleep(2)
def main(self):
threading.Thread(target=telegram().main).start()
threading.Thread(target=self.run).start()
class telegram:
def __init__(self):
pass
def main(self):
while True:
sleep(8)
print('A message was recieved!')
program().paus()
When a message is received the function is run and prints successfully, but the variable self.pausing
isn't changed.
I guess I'm misunderstanding something about self.* variables. My expected output would be the variable to be changed.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…