astro-pi / beta-testing

Bug tracker for the Trinket Sense HAT emulator
https://trinket.io/sense-hat
3 stars 0 forks source link

Tight loops with no sleep #12

Closed davidhoness closed 8 years ago

davidhoness commented 8 years ago

I've found an issue where a while loop without any timing delays causes the browser to think it's a rouge script and presents a dialogue to force it to stop. This code reproduces it on FF.

from sense_hat import *

sense = SenseHat()

while True:
    sense.set_pixel(0,0, 255,255,255)

After manually clicking Stop script the following error is thrown from right down inside Skulpt;

[Exception... "Unexpected error" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame :: https://trinket-cdn.trinket.io/361592c4-skulpt.min.js :: Sk.misceval.asyncToPromise :: line 270" data: no] in https://trinket-cdn.trinket.io/361592c4-skulpt.min.js

One possible solution to this would be to force a time delay inside a while loop that doesn't implement any explicitly. I think we need to avoid tripping the browser's own script protection mechanisms.

FireFox 47.0, Mozilla Firefox for Ubuntu canonical - 1.0. Linux 3.13.0-91-generic #138-Ubuntu SMP Fri Jun 24 17:00:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

eah13 commented 8 years ago

Thanks for reporting. We're looking into a solution similar to what you've described.

eah13 commented 8 years ago

This is fixed! While loops without sleeps will no longer freeze the browser and can be stopped with the stop button.