[python] How to stop a function