Skip to content
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

Unable to pass arguments to a function which uses timeout_decorator with use_signals = False #32

Closed
akshay-hazari opened this issue Jan 31, 2017 · 3 comments

Comments

@akshay-hazari
Copy link

akshay-hazari commented Jan 31, 2017

import timeout_decorator

class abc:
    @timeout_decorator.timeout(5, use_signals=False)
    def mytest(self,arg):
        print "Start",arg
        for i in range(1,10):
            time.sleep(1)
            print "%d seconds have passed" % i

if __name__ == '__main__':
    abc().mytest("arg")

Gives an error :
TypeError: mytest() takes exactly 2 arguments (1 given)

@akshay-hazari akshay-hazari changed the title Unable to pass arguments to a function using timeout_decorator Unable to pass arguments to a function using timeout_decorator when use_signals = False Jan 31, 2017
@akshay-hazari akshay-hazari changed the title Unable to pass arguments to a function using timeout_decorator when use_signals = False Unable to pass arguments to a function which uses timeout_decorator with use_signals = False Jan 31, 2017
@leviable
Copy link
Contributor

I'm not entirely sure how the _Timeout class works, but it seems like it has trouble working with class methods specifically. If you alter akshay-hazari's code to just be a function, it works fine. Some initial debugging shows that the instance reference for the abc object isn't being passed into the __call__ method:

    def __call__(self, *args, **kwargs):
        """Execute the embedded function object asynchronously.

        The function given to the constructor is transparently called and
        requires that "ready" be intermittently polled. If and when it is
        True, the "value" property may then be checked for returned data.
        """
        from pprint import pprint as pp
        import pdb
        pdb.set_trace()
        self.__limit = kwargs.pop('timeout', self.__limit)
        self.__queue = multiprocessing.Queue(1)
        args = (self.__queue, self.__function) + args
        self.__process = multiprocessing.Process(target=_target,
                                                 args=args,
                                                 kwargs=kwargs)

Using the example code:

(.venvtomp) ➜  tmp python timeoutdec.py
> /Users/levi/tmp/.venvtomp/src/timeout-decorator/timeout_decorator/timeout_decorator.py(125)__call__()
-> self.__limit = kwargs.pop('timeout', self.__limit)
(Pdb) pp(args)
('arg',)

My best guess is that the function needs to be wrapped using functools.wraps or functools.update_wrapper, but I'm not sure where that should actually happen.

@dabercro
Copy link

@akshay-hazari You could do the following workaround if you don't want to wait for an update:

if __name__ == '__main__':
    abc_obj = abc()
    abc_obj.mytest(abc_obj, "arg")

@k2fong
Copy link
Contributor

k2fong commented Apr 13, 2017

This should be resolved by the merge for #35. Recommend closing.

@pnpnpn pnpnpn closed this as completed Jun 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants