-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding class support #42
Conversation
I personally dont like that the wrapped part is duplicated over and over. If You want to access custom (class or other) attributes, You can use smt. like : def timeout(seconds=None, use_signals=True, timeout_exception=TimeoutError, exception_message=None, custom_timeout_attribute=False):
...
if custom_attribute is not None:
new_seconds=eval(custom_timeout_attribute) Its just a markup - didnt look at the old code that accurately, since my code already derived a lot from the old version. I will probably set up a new project, because I wrote a very nice retry decorator also, that will need my new fork of the timeout decorator ... Now You can do (almost) anything You want. class Foo(object):
def __init__(self, x):
self.x=x
@timeout(custom_timout_attribute='instance.x*2')
def foo2(self):
do something interesting what You need to think of is - who will "win" - the custom_timeout_attribute or the kwarg possibly passed to the method ? : class Foo(object):
def __init__(self, x):
self.x=x
@timeout(custom_timout_attribute='instance.x*2')
def foo2(self):
do something interesting
>>> my_foo = Foo(3)
>>> my_foo.foo2(timeout=5) # who should win here ? the popped kwarg or the custom attribute ?
# and is it really neccessary to access special attributes
# if You can pass new timeout by kwarg ? |
hey, I added the eval idea into my project. give it a try (and if You want, make some tests for it) ... yours sincerely |
Hello,
I've added a use_class_attribute=False optional flag which, if set to True, override seconds with self.timeout if it exists (raising AttributeError if not).
I've also added a test for this and updated version, changes and README accordingly.