Skip to content

fix: add timeout for code runner#377

Merged
imDarshanGK merged 2 commits into
imDarshanGK:mainfrom
pavsoss:timeout-code-runner
Jun 11, 2026
Merged

fix: add timeout for code runner#377
imDarshanGK merged 2 commits into
imDarshanGK:mainfrom
pavsoss:timeout-code-runner

Conversation

@pavsoss

@pavsoss pavsoss commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes the Code Runner plugin hanging on long-running Python snippets by enforcing execution time limits and adding regression tests to prevent future failures.

While implementing the timeout fix, the Code Runner execution command was also updated to use the current Python interpreter (sys.executable) instead of a hardcoded python3 command, improving compatibility across Windows, macOS, Linux, and virtual environments.

Changes Made

Backend Updates

plugins.py

  • Replaced the hardcoded python3 execution command with sys.executable.
  • Added/updated timeout handling for long-running code execution.
  • Ensured timeout failures return a controlled error response instead of leaving the request hanging.

Tests

test_api.py

  • Added test_coderunner_success to verify that normal Python snippets execute successfully and return expected output.
  • Added test_coderunner_timeout to verify that infinite loops or long-running snippets are terminated after the configured timeout period.

Before

  • Code Runner could hang indefinitely when executing snippets such as:
while True:
    pass
image

After

  • Long-running snippets are automatically terminated after the timeout duration with a clear error response.
  • Code execution works consistently by using the active Python interpreter.
  • Normal snippets continue to execute successfully.
image

Testing

Verified locally by running the test suite:

pytest -v

All tests passed successfully, including the new Code Runner execution and timeout regression tests.

Result

The Code Runner is now more reliable, cross-platform compatible, and protected against indefinitely running snippets.

Closes #237

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

@pavsoss is attempting to deploy a commit to the Darshan's projects Team on Vercel.

A member of the Team first needs to authorize it.

@imDarshanGK imDarshanGK added SSoC26 Part of Social Summer of Code 2026 Hard Larger or more advanced changes labels Jun 11, 2026
@imDarshanGK imDarshanGK merged commit 49ea4d6 into imDarshanGK:main Jun 11, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hard Larger or more advanced changes SSoC26 Part of Social Summer of Code 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: plugin runner should timeout long-running snippets

2 participants