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_executor.py 无法在windows平台运行 #378

Open
Wang-Jun-Chao opened this issue Oct 11, 2024 · 0 comments
Open

python_executor.py 无法在windows平台运行 #378

Wang-Jun-Chao opened this issue Oct 11, 2024 · 0 comments

Comments

@Wang-Jun-Chao
Copy link

Traceback (most recent call last):
File "D:\IdeaProjects\Qwen-Agent\qwen_agent\tools\python_executor.py", line 139, in execute
timeout(timeout_length)(runtime.exec_code)('\n'.join(code))
File "D:\IdeaProjects\Qwen-Agent\venv\lib\site-packages\timeout_decorator\timeout_decorator.py", line 75, in new_function
old = signal.signal(signal.SIGALRM, handler)
AttributeError: module 'signal' has no attribute 'SIGALRM'. Did you mean: 'SIGABRT'?
('', "AttributeError: module 'signal' has no attribute 'SIGALRM'. Did you mean: 'SIGABRT'?")

venv/Lib/site-packages/timeout_decorator/timeout_decorator.py
def decorate(function):

    if use_signals:
        def handler(signum, frame):
            _raise_exception(timeout_exception, exception_message)

        @wraps(function)
        def new_function(*args, **kwargs):
            new_seconds = kwargs.pop('timeout', seconds)
            if new_seconds:
                old = signal.signal(signal.SIGALRM, handler)
                signal.setitimer(signal.ITIMER_REAL, new_seconds)

            if not seconds:
                return function(*args, **kwargs)

            try:
                return function(*args, **kwargs)
            finally:
                if new_seconds:
                    signal.setitimer(signal.ITIMER_REAL, 0)
                    signal.signal(signal.SIGALRM, old)
        return new_function

timeout_decorator需要区分windows和liunx平台

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

1 participant