Background task time-out
-
@Christoph-Hart I get a strange time-out issue with the background task if the panel timer is set too high, but not if it is set lower. In my case 100ms works, but not above 200ms. The value might be system dependent...
HiseSnippet 1232.3ocsW01aaaCDlJIZHxqsXEX+.HxmTVybr8Z6FPVvb7aIFswwHNsaECaELRzVDghzfhNIFa4+19IsusOtcTR1RJwwI0XU.I.7t6g2yc7Huy8UROZTjTgrbNa5XJx5I1ClJzAMCHLApaKj0yrOlDooJbhnFSGShhn9HKq0OzHvxYCT72e+SMHbhvilIBgduj4QeKKjoyj1u9aXbdGhO8LVXNqeY8tdRQSIWNA3y51UPiIdWPFQ6QLlslMx5KZ6yzR0.MQSiPVazP5OcPf7JQh8umEwNmSMKphF.aTh3NRtugwFonlALte+YwcDB1k9YYg0SxBes8wLe1b4YYiuJVANCQ97g0ZEo25EnW07zqRN5s.JYkiRajPomaOvSwFqyzX3yWZ2U.GNCIPZOOURrEs1+Xa2TBVHzkCIWP6nfEyQ395JU1AC+a68JAVEI4zxdbJQ4BBJAmEQZ7kDEtOQP4UwNNN6imsain5lxvwRArvcqDK1BfkgpwDsVJVJrTSVDtZOLtZEwcNTrLRImH7OiDcAF.2VLhIfPRQgyiFET6tUQyMaUoR6tKd+66KIKrD8kRRBkin59P4h9T4DM3d2gSDdZlT3NZ6R+QImQkGBU+Gv4tIU5QkOmCTA7OnJxDlFoyUNRQohoTNWdUhIFzs4b13Hp6upCXQlbyOy70Atai+F7wDcPYEQ3KCc2dG7LCNhxFEnWjEUqX962fM+FSNHKHLWNUMIbtISkEEwAQ71pniMwoaJzYH0DUBV2pwUV6t6c07pXMOTF+HJ4xo3NoddYo9YrCGXfzo.WmUYOVYH6VCN6fSOqcq3CbmgRE1ksek8vreDXa72drW7hsK4.HcLkUWi2Gylk152EuawDHbl3XLIVHWNx85XQFjSAwWCKtojycXQmt85N3nDZbyClH5IUgDN1bXrrr.SvgBN77jgTjdAybKRI4tdytBsCbigOgFmeXCwtoqbbtU9CH2dkR2jjhy3MZdUws8fIotzHowgqbTT6wGEEuaW1C73IhbO.D.uH36VHVyGp0VVnVKWnVJGI6I0zSRK4fiT7sUMb3B0ktab3RwhTmbcYI.cESBOmpxmJLFBsMJ1Kx996EkuUoWx6s4LTJ5JX5SFSE2WCTT5izPeq0RYEXpNtq0yR6Zkj6PLn4jicZMCJlx4mV.8I.u1Bf+ttsHZho+YJk.ZNlpzLSFvpE8RXXjjtoN1snQWnkiAWMuwBLeQhae5rdslGth85l1IOhgtNygen9z7Ktx7Fblfo0Cheyctj+RUGkyUa9HRP4b1umyY3+rtldsYOr6cxoGevaQ2x29212nV0YQGKCAOSTvFYs1mFUpkmJ5EQkmX23flu4vSO4c8ZsJz4tC7.iZI8mvI5hyeYF5LUAbQnvPOlAaDQL8z7Ck9+1PYOVJ9b69LsWvh43ZKfil6MeF3X5nrO0t8vgTOcFA2vtyu74YtUTxLOiflgJFTwX2aR3.XLFOJ3cAb+w7PDbXafFuthYsICLfJ7iW7uvWpxpl0VoJqNSIJj3ojezK4kByvxaFKA3jH92I3.+fEXMd96K11UJWAEBys+QOOS3+svqXKFSsU.y2sBXd4Jf4Uq.lWuBX99U.yOrTLlexzASzxvjqCff9sien1xpsf.UVwUgn+C33GHjG
-
My bad... Apparently
shouldAbort
is mandatory for it to work. -
I'm not sure the time-out method has an effect...
Unless it is reset at each shouldAbort verification?HiseSnippet 1353.3ocsWstaaaCElJIZMxqsXEXO.D4WxqsN9Ra2.xBlulVi1XaDm10ggsNFIZahPQZPQmFisf8psGo8Frcnnrsbpiap2pBRP34BOemOdH4g8Tx.ZbrTgb7Nc5XJx4tt8mJziZLhvDn1MQN228XRrlpvVQ0mNlDGSCQNNa+bi.GucPIe+8OTmvIh.5BQHzajr.5qXQL8Bo8p9RFmeDIjdJKJi0OoZ6.ongjKm.3Ya2hnwjfyICocHFy1xE47EsBYZopulnowHmcpKCm1ej78Bq8ugEyNiSMCJg5CSjU7QRdnAwFonFiX7vdyx6XDLK8VvBaaYgu18XVHat7ErwWkn.uvir7gyV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X3+npldoYNb6z8jiq8Jz0hc30iMpYUV7wxHHxDELQNa8oAkxYghdUP4tt0q03kO+jtutSyO6voxMAmp+YJbtias5cO4zMAIeXKxPy4xvIbhd4N1MOSIUArido1jMsBKhY5oYeFy+asweag3Cb6wzAiVMF2ZEXD1474.ioO94dtsFLfFnW.vcbO5seddoCx1C7PnOFECJVb6LIpOzVa.Eht.1IaNQEVrMtlLtnYrgA5C24jL3efuTkkLicRUVZlRTDIPIeWf8LKyyq1MQBfIQxKK8fm3BiwyOnz0sXghnH3kduKHvj9OFNNd09TdC7oxF3yS1.ed5F3yy1.e91Mvmuas9XdjcsIZYjc6.HnWqjqLbbZIHPkURUH5egUrnZt
-
@ustk two things:
- the function you pass into
callOnBackgroundThread
must have a parameter that will contain a reference to the thread where it's called. - You need to call
thread.shouldAbort()
in the loop in order to avoid the timeout (and break the execution if it returns true). This is a safety procedure to prevent you from doing stupid things.
I'm not sure the time-out method has an effect...
Everytime you call
shouldAbort
, the maximum execution time will get bumped by the timeout value you specifiy withsetTimeOut()
, so this gives you a bit more control over the execution. - the function you pass into
-
@christoph-hart In my case, I am using nested functions, and everything seems to work fine, but I'm afraid I didn't do it cleanly.
If I resume, this grossly is what I do:const var backgroundTask = Engine.createBackgroundTask("backgroundTask"); inline function oncomputeBtnControl(component, value) { if (value) backgroundTask.callOnBackgroundThread(compute); else backgroundTask.sendAbortSignal(false); }; computeBtn.setControlCallback(oncomputeBtnControl); inline function compute(backgroundTask) { // define some parameters and start two analysis analyse(par1, par2, par3); analyse(par4, par5, par6); if (backgroundTask.getStatusMessage() != "aborted") { // Treat as "all good", reset btn, etc... } else { // Do something else } } inline function analyse(x, y, z) { // Heavy loop for (i=0; i<bigloopsize; i++) { if (backgroundTask.shouldAbort()) { backgroundTask.setStatusMessage("aborted"); return; } // Some heavy stuff, but less than time-out so no need for it } }
As I said, this works apparently smoothly, but I'm not sure I did it right.
What is strange (but this is the behaviour I want anyway), is that if I cancel during the first analysis, the second doesn't seem to run (again it is good for me, but strange because the "Do something else" is treated...)
Maybe because shouldAbort is still true until we exit compute, or maybe until the next background thread call... -
backgroundTask.getStatusMessage() != "aborted"
Why don't you use
shouldAbort()
there too? Using the status message seems unnecessary. -
@christoph-hart Ah ok! So this confirms the rests :)
-
Maybe because shouldAbort is still true until we exit compute, or maybe until the next background thread call...
Yes.
-
With the latest commit I'm occasionally seeing
Execution timed-out
errors when switching presets, I'm not using any backgroundTasks. -
@d-healey Me too