0

I want to count imported class' methods executions while script running. And stop the script according the method executions limit.

I tried to use the __getattribute__ to count executions in inherited class, but it is too hard to use it for such a simple problem (at least at first glance).

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Why don't you just keep an internal counter of each time a method is called and handle the logic in the method. You might even make a decorator out of it – juanpa.arrivillaga Aug 12 '19 at 22:58
  • @juanpa.arrivillaga - I just want to simply count an external imported lib's methods runs through script execution. How can I do this? – ritamiskas Aug 12 '19 at 23:00
  • Then perhaps you should just use a proxy class that does the counting – juanpa.arrivillaga Aug 12 '19 at 23:01
  • Maybe try a static variable (aka not tied to any particular instance of the class). Then increment from within whatever methods you want to count the use of. – Andrew Grass Aug 12 '19 at 23:01
  • There are generic ways to "wrap" every method of a class. See [How to wrap every method of a class?](https://stackoverflow.com/questions/11349183/how-to-wrap-every-method-of-a-class) for example. Also see answers to [How to make built-in containers (sets, dicts, lists) thread safe?](https://stackoverflow.com/questions/13610654/how-to-make-built-in-containers-sets-dicts-lists-thread-safe) – martineau Aug 12 '19 at 23:35

0 Answers0