@@ -36,6 +36,8 @@ import embed from "vega-embed";
3636window . vegaEmbed = embed ;
3737
3838var isMouseDown = false ;
39+ var stopExecution = false ;
40+
3941document . onmousedown = function ( ) {
4042 isMouseDown = true ;
4143} ;
@@ -97,6 +99,7 @@ export class ActiveCode extends RunestoneBase {
9799 this . historyScrubber = null ;
98100 this . timestamps = [ "Original" ] ;
99101 this . autorun = $ ( orig ) . data ( "autorun" ) ;
102+ this . outputLineCount = 0 ;
100103 if ( this . chatcodes && eBookConfig . enable_chatcodes ) {
101104 if ( ! socket ) {
102105 socket = new WebSocket ( "wss://" + chatcodesServer ) ;
@@ -1074,6 +1077,7 @@ Yet another is that there is an internal error. The internal error message is:
10741077 }
10751078 outputfun ( text ) {
10761079 // bnm python 3
1080+ if ( this . outputLineCount > 1000 ) return ;
10771081 var pyStr = function ( x ) {
10781082 if ( x instanceof Array ) {
10791083 return "[" + x . join ( ", " ) + "]" ;
@@ -1099,11 +1103,21 @@ Yet another is that there is an internal error. The internal error message is:
10991103 . replace ( / < / g, "<" )
11001104 . replace ( / > / g, ">" )
11011105 . replace ( / \n / g, "<br/>" ) ;
1106+ // todo: try to make this use the suspension mechanism in skulpt
11021107 return Promise . resolve ( ) . then (
11031108 function ( ) {
11041109 setTimeout (
11051110 function ( ) {
1106- $ ( this . output ) . append ( text ) ;
1111+ if ( this . outputLineCount < 1000 ) {
1112+ $ ( this . output ) . append ( text ) ;
1113+ this . outputLineCount += 1 ;
1114+ } else {
1115+ if ( this . outputLineCount == 1000 ) {
1116+ $ ( this . output ) . append ( "Too Much output" ) ;
1117+ this . outputLineCount += 1 ;
1118+ stopExecution = true ;
1119+ }
1120+ }
11071121 } . bind ( this ) ,
11081122 0
11091123 ) ;
@@ -1318,6 +1332,7 @@ Yet another is that there is an internal error. The internal error message is:
13181332 */
13191333 async runProg ( noUI , logResults ) {
13201334 console . log ( "starting runProg" ) ;
1335+ this . outputLineCount = 0 ;
13211336 if ( typeof logResults === "undefined" ) {
13221337 this . logResults = true ;
13231338 } else {
@@ -1373,6 +1388,13 @@ Yet another is that there is an internal error. The internal error message is:
13731388 try {
13741389 await Sk . misceval . asyncToPromise ( function ( ) {
13751390 return Sk . importMainWithBody ( "<stdin>" , false , prog , true ) ;
1391+ } , { // suspension handlers
1392+ "*" : ( ) => {
1393+ if ( stopExecution ) {
1394+ console . log ( "stopExecution is true" )
1395+ throw new Error ( `Too much output` ) ;
1396+ }
1397+ } ,
13761398 } ) ;
13771399 if ( ! noUI ) {
13781400 if ( this . slideit ) {
0 commit comments