Possible help for extra-time-consuming operations?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible help for extra-time-consuming operations?

Quentin Long
Have pondered the issue of ensuring that the OS does *not* label a seemingly-'frozen' LC app as unresponsive. The following code (which I haven't actually tried in LC, shame on me) might be helpful. Some notes after the code…

========================

local KeepMeAlive = false
local NumSecs = 4

on LifeLine DerStatus

case DerStatus = "on"
put true into KeepMeAlive
TickleMe
break

case DerStatus = "off"
put false into KeepMeAlive
break

default
exit to top
end case

end LifeLine

on TickleMe
if KeepMeAlive = true then send "TickleMe" to me in NumSecs seconds
end TickleMe

========================

How to use this code: Put the code into your stack script, or a backscript, or wherever, as you deem appropriate. When a handler has a time-consuming chunk of code in it, do the following:

LifeLine ("on")

-- Time-consuming
-- chunk
-- of
-- code

LifeLine ("off")

I used the case structure to provide for any future use-case in which you want more options than just "keep this thing alive" or not. NumSecs is a local variable so that it can be easily adjusted in case this code is run under an OS that thinks, say, 2 seconds is a long-enough period to justify treating an app as unresponsive.

========================

It occurs to me that if you're looking for specific strings in a Very Large File, and you're reading the VLF in N-character-long chunks, you want to be careful that you don't overlook instances of a sought-for string which have a between-chunks boundary within them.

Say you're reading 1000-character chunks, and your sought-for StringX *starts* at char 999 within the VLF. In this case, only character 1 of StringX will be found within the first chunk; only characters 2 thru -1 of StringX will be found within chunk 2. If you *just* look *within* each chunk as you read it, you won't find the instance of StringX which started at character 999.



"Bewitched" + "Charlie's Angels" - Charlie = "At Arm's Length"
Read the webcomic at [ http://www.atarmslength.net ]!
If you like "At Arm's Length", support it at [ http://www.patreon.com/DarkwingDude ].
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Possible help for extra-time-consuming operations?

J. Landman Gay
On 4/15/2016 8:25 PM, Quentin Long wrote:

> Have pondered the issue of ensuring that the OS does*not*  label a
> seemingly-'frozen' LC app as unresponsive. The following code (which
> I haven't actually tried in LC, shame on me) might be helpful. Some
> notes after the code…
>
> ========================
>
> local KeepMeAlive = false
> local NumSecs = 4
>
> on LifeLine DerStatus
>
> case DerStatus = "on"
> put true into KeepMeAlive
> TickleMe
> break
>
> case DerStatus = "off"
> put false into KeepMeAlive
> break
>
> default
> exit to top
> end case
>
> end LifeLine
>
> on TickleMe
> if KeepMeAlive = true then send "TickleMe" to me in NumSecs seconds
> end TickleMe
>
> ========================

How great to see you on the list! Been a while.

I'm afraid the technique won't work though. The first "tickleMe" will
trigger when the local is set to "on" but after that a long handler
won't return control to the queue until it finishes, so any pending
"tickleMe" messages won't execute until the long handler is finished.
The fix is to wait 0 with messages inside the long handler, which yields
time to the engine and allows LC to do housekeeping. That works best
inside a repeat loop, otherwise it gets iffy.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode