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

Unexpected behaviour when using timeout #84

Open
raghunadhNarne opened this issue Mar 29, 2024 · 0 comments
Open

Unexpected behaviour when using timeout #84

raghunadhNarne opened this issue Mar 29, 2024 · 0 comments

Comments

@raghunadhNarne
Copy link

raghunadhNarne commented Mar 29, 2024

Hi,
Here in python_runner.py file i am reading a python file(myscript.py) and running the script with timeout.

python_runner.py:

import timeout_decorator
try:
        @timeout_decorator.timeout(5)
        def execute_script_file_with_timeout():
            exec(open(myscript.py).read())
        execute_script_file_with_timeout()
    except timeout_decorator.timeout_decorator.TimeoutError:
        print("Task Execution Timeout")

when i use this script in myscript.py, this is working as expected.

import random
import string
print("\n".join("".join(random.choices(string.ascii_uppercase, k=1024))))

when i use this script in myscript.py,

import random
import string
print("\n".join("".join(random.choices(string.ascii_uppercase, k=1024)) for _ in range(1024)))

i am getting below error,

Traceback (most recent call last):
File "python_runner.py", line 56, in
execute_script_file_with_timeout()
File "/home/user1/.local/lib/python3.8/site-packages/timeout_decorator/timeout_decorator.py", line 82, in new_function
return function(*args, **kwargs)
File "python_runner.py", line 55, in execute_script_file_with_timeout
exec(open(myscript.py).read())
File "", line 7, in
File "", line 7, in
NameError: name 'random' is not defined

Thanks, Raghu

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