[英]How to stop a script in skulpt
I made a skulpt project for my students.我为我的学生做了一个 skulpt 项目。 Every time they made an infinite loop, the browser crashes and the code is gone.
每次他们进行无限循环时,浏览器都会崩溃并且代码消失了。 That is very frustrating for the students.
这对学生来说是非常令人沮丧的。 I saw a stop button on https://trinket.io/python , but don't understand how they made it.
我在https://trinket.io/python上看到了一个停止按钮,但不明白他们是怎么做到的。 I followed the instructions on http://www.skulpt.org/ to integrate skulpt in my site.
我按照http://www.skulpt.org/上的说明将 skulpt 集成到我的站点中。
Any ideas?有任何想法吗?
Not particularly well documented - there are certain options that you can add to the Sk.configure
one of which is execLimit
in ms.没有特别详细的记录 - 您可以将某些选项添加到
Sk.configure
,其中之一是execLimit
in ms。
eg From the example http://skulpt.org/using.html例如来自示例http://skulpt.org/using.html
Sk.configure({output:outf, read:builtinRead, execLimit: 5000});
Skulpt will raise a TimeLimitError
if the execLimit
is reached. Skulpt将引发
TimeLimitError
如果execLimit
达到。
in terms of the cancel button - there's an additional setting yieldLimit
which you can set in ms
.在取消按钮方面 - 有一个额外的设置
yieldLimit
您可以在ms
设置。 This will essentially pause the execution at intervals.这基本上会每隔一段时间暂停执行。 And you can add a handler to deal with this pause.
你可以添加一个处理程序来处理这个暂停。
Again not documented well by Skulpt but here's a JS Fiddle that is proof of concept: Skulpt 再次没有很好地记录,但这里有一个 JS Fiddle 是概念证明:
https://jsfiddle.net/bjLuq5s7/ https://jsfiddle.net/bjLuq5s7/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.