I wrote a short example because I can't share my original codes. I think the problem was caused by python itself. Anyway, when I start a thread for a class, the program crashes if there are conditions. What is the reason? What is also the possible solution.
from threading import Thread
global dicta
dicta={"number":0,"name":"John","animal":"pig"}
class PigMan:
def __init__(self):
Thread(target= self.iAmFool).start()
def iAmFool(self):
if dicta["number"]==0:
print("It's work")
else:
print("Wtf")
PigMan()
I expected it to run smoothly, but this is the error:
Traceback (most recent call last):
File "C:/Users/Pig/Desktop/test.py", line 13, in <module>
PigMan()
File "C:/Users/Pig/Desktop/test.py", line 6, in __init__
Thread(target= self.iAmFool).start()
AttributeError: 'PigMan' object has no attribute 'iAmFool'