I am working on a website that has a simple IDE. I am using code mirror as the editor. I would like to set a timer so that if the code in code mirror has an inifinite loop, pyscript will terminate the code from code mirror without causing issues for the website as a whole. I have seen stack overflow questions about doing this in python but the solutions have not worked in pyscript. I have written a javascript function that times out javascript code.
Is there something built into pyscript to handle this? After researching this some more, I came across setTimeout in the documentation, but it is not doing what I was hoping that it would do.
Any help on this would appreciated.
@Behailu_Getachew Thanks. Can you provide little more detail? As I said in my original post, I have looked into Timeout and have not been able to get it to work.
This is psuedocode what I have so far. It is running the timer before the code starts.
def unloadCode():
if not codeCompleted:
raise ZeroDivisionError(“Division by zero!”)
return “var OK”
def executeCode(code, inputs, output):
window.setTimeout(create_proxy(unloadCode()), int(5 * 1000), “OK”)
runCode
window.clearTimeout(“OK”)
The documentation on the pyscript website is not clear to me. I am not familar with proxies. I based this algorithm off of this page. Window setTimeout() Method
My issue is that:
window.setTimeout(create_proxy(unloadCode()), int(5 * 1000), “OK”)
should be:
window.setTimeout(create_proxy(unloadCode), int(5 * 1000), “OK”)