Skip to content

Comments

Catch infinite loops#14

Open
prestonraab wants to merge 6 commits intomasterfrom
catch-infinite-loops
Open

Catch infinite loops#14
prestonraab wants to merge 6 commits intomasterfrom
catch-infinite-loops

Conversation

@prestonraab
Copy link

@prestonraab prestonraab commented Nov 29, 2023

This draft works, but is not ideal.
The goal is to throw an exception when student code is in an infinite loop.
This is triggered when the student's code has taken more than six seconds to run.
This is in the dialog checker, so it's not run for the bit Units.

The hard problem is creating a killable process that modifies local variables.

runpy.run_path(script_name, _globals, module) can modify local variables through its global argument.

multiprocessing.Process() creates a killable process, but its pickling requirement makes modification difficult.

My current solution runs the process once using multiprocessing.Process() to check if the code contains an infinite loop. If it does, we stop testing the student's code and throw an exception. If it does not, we run the code again using runpy.run_path and process their output as normal.

Creating the timer and process currently works.

However, adding any global to runpy causes it to fail.

For sys, that's because multiprocessing can't process a module object. But I'm not sure why adding 'input' causes the process to stop immediately.
Checks for infinite loops in a killable process the first time.
Second time, intercepts output
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

Successfully merging this pull request may close these issues.

1 participant