Is it possible to cancel an exec() in python after 5 seconds

QuestionsIs it possible to cancel an exec() in python after 5 seconds
sethbeckerman5 Staff asked 4 years ago

I am working on a python script that runs small user generated scripts. There is a problem though when a user submits a script that infinitely loops. I was wondering if it would be possible to stop an exec() after 5 seconds of running.

something like this ^
So far I tried using threading but the results were mixed. I threaded a function called main which would run their code through exec then I would delete the thread after 5 seconds but it was buggy.


View on Stack Overflow