Anyways, usually I did that setting some flag so that the second time a function is called, it'd check that flag and would skip the function in the second time.
After tinkering a bit about it, I came with a shorter version changing the function code which I thought is pretty nice:
def func(): print 'Calling func only this time' func.func_code = (lambda:None).func_code
Now, calling it a second time will actually execute the lamda:None code.
Yes, I know you'll say it's cryptic, so, I'm including a decorator version below which does the same checking with a variable:
@call_only_once def func(): print 'Calling func only this time' def call_only_once(func): def new_func(*args, **kwargs): if not new_func._called: try: return func(*args, **kwargs) finally: new_func._called = True new_func._called = False return new_func