xxxxxxxxxx
class MyClass(object):
def __init__(self):
self.first_warning = False
def func(self):
if(condition) and not self.first_warning:
warnings.warn('warn message',RuntimeWarning)
self.first_warning = True
m = MyClass()
m.func() # only the first time the condition is met, the warning will occur
m.func()
m.func()