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

Python 3 support #2

Closed
deeplook opened this issue Sep 25, 2014 · 3 comments
Closed

Python 3 support #2

deeplook opened this issue Sep 25, 2014 · 3 comments

Comments

@deeplook
Copy link
Contributor

A suggestion to make this Python 3 compliant, note the test for PY_VERSION:

import sys
PY_VERSION = sys.version_info[0]
# ...
def timeout(seconds_before_timeout):
    def decorate(f):
        def handler(signum, frame):
            raise TimeoutError()
        def new_f(*args, **kwargs):
            old = signal.signal(signal.SIGALRM, handler)
            signal.alarm(seconds_before_timeout)
            try:
                result = f(*args, **kwargs)
            finally:
                signal.signal(signal.SIGALRM, old)
            signal.alarm(0)
            return result
        if PY_VERSION == 2:
            new_f.func_name = f.func_name
        elif PY_VERSION == 3:
            new_f.func_name = f.__name__
        return new_f
    return decorate
@pnpnpn
Copy link
Owner

pnpnpn commented Sep 25, 2014

Can you make a pull request? Thanks!

@deeplook
Copy link
Contributor Author

Sorry, too busy...

toddsifleet added a commit to toddsifleet/timeout-decorator that referenced this issue Oct 16, 2014
* This will ensure that the func_name/doc strings is correct across py versions
* Fixes issue pnpnpn#2
@toddsifleet
Copy link
Contributor

This issue was resolved by #5

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

3 participants