detect unresponsive scripts

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

detect unresponsive scripts

23 Dec 2016, 02:06

every so often, probably due to heavy CPU usage by another program,
all of my hotkeys/hotstrings fail to work, especially on a low-spec netbook,
(a) I could kill all the processes and reopen,
(b) I could reload all the processes, wait, and kill/reopen the ones that hadn't reloaded,
- both approaches are undesirable for different reasons
- also some scripts may not have hotkeys, but I'd want to programmatically confirm they were still running
- perhaps I could add an OnMessage function to all scripts, that would respond to confirm whether they were still running, but this is also undesirable
- there are at least two types of 'unresponsive' (script has failed, script working but hotkeys/hotstrings have failed)

is there a reliable way to establish whether a script is unresponsive/what kind of 'unresponsive' it is?
also, is there a way to deliberately make a script unresponsive,
in order to test methods on them?
thank you!
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: detect unresponsive scripts

23 Dec 2016, 04:50

If the failing hotkeys are context sensitive, consider
#IfTimout wrote: If the system timeout value is exceeded, the system may stop calling the script's keyboard hook, thereby preventing hook hotkeys from working until the hook is re-registered or the script is reloaded. The hook can usually be re-registered by suspending and un-suspending all hotkeys.
Source
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: detect unresponsive scripts

23 Dec 2016, 05:35

Helgef makes a good point. If you're using hooked hotkeys (Using #UseHook,On, hotkeys prepended with $ or conditional hotkeys preceded by #If blabla), Windows may have stopped calling AHK's hook, killing your hotkeys. But it will then have already exceeded the #Timeout value because of other reasons. You can increase the Windows timeout value in the registry, but that will negatively impact the responsiveness of the netbook during times of high load.

If you haven't explicitly called #InstallKeybdHook and #InstallMouseHook, suspending and unsuspending the script will unually reload the hook, reviving your hotkeys. Try that manually next time.

There's an example of doing that for all script using PostMessage here: https://autohotkey.com/board/topic/8928 ... ntry565650
You could create that as a separate script triggered by a non-hook hotkey.

The above is to recover from a dropped hook, to prevent it all together you could try increasing the AHK process priority to above normal using Process,Priority,....... That will make sure AHK gets system resources before most other processes, so it won't have to wait as much, reducing the risk of time-outs.
Last edited by Nextron on 23 Dec 2016, 06:10, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: detect unresponsive scripts

23 Dec 2016, 05:41

@Helgef
this is interesting information thank you, glad I asked
(if it's of any relevance, I only use #IfWinActive, and not #If expressions,
32-bit v1.1.16.05, on 64-bit Windows 7)

will try, next time my scripts get disrupted:

Code: Select all

DetectHiddenWindows, On
WinGet, hWnd, ID, %vPath% - AutoHotkey v ahk_class AutoHotkey
SendMessage, 0x111, 65305, , , ahk_id %hWnd% ;toggle suspend
MsgBox %ErrorLevel%
PostMessage, 0x111, 65305, , , ahk_id %hWnd%
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: detect unresponsive scripts

23 Dec 2016, 05:50

@Nextron
thanks very much for the points and for the link,
- checking for a menu item tick to establish paused/suspended status, very good,
I was wanting a way to do that!
- and a menu loop to jog (update) the menu, I was wondering about that too!
- furthermore retrieving information from the menus
could give some indication of script responsiveness without affecting
the script in any way or making windows appear
(unlike open/reload/edit/exit/suspend/pause)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: detect unresponsive scripts

23 Dec 2016, 05:51

jeeswg wrote: (if it's of any relevance, I only use #IfWinActive, and not #If expressions,
The quote from the docs would apply to hotkeys under #IfWinActive too, and as pointed out by Nextron, it would be relevant for all hooked hotkeys.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: detect unresponsive scripts

23 Dec 2016, 05:53

whew, thought it might, but I've learnt never to assume with computers
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: detect unresponsive scripts

23 Dec 2016, 06:11

Also: The above is to recover from a dropped hook, to prevent it all together you could try increasing the AHK process priority to above normal using Process,Priority,....... That will make sure AHK gets system resources before most other processes, so it won't have to wait as much, reducing the risk of time-outs.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: detect unresponsive scripts

23 Dec 2016, 09:12

Hmm well I usually have about 17 scripts running simultaneously,
so I don't know if I should make them all high priority.
Let's say all that was running was AHK scripts and Google Chrome,
would making Google Chrome high priority, keep it happy and actually help prevent it
from crashing the AHK scripts? (I'm not an expert on these matters.)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: detect unresponsive scripts

23 Dec 2016, 09:35

17 AHK instances, that's quite a few. Perhaps consolidating some of the scripts would help too.

System resources are equally shared between processes of the same priority that request them. Only when resources remain unused are they made available to lower priority processes. AHK does not require much CPU time to process the hook conditions, but if it's delayed because of another process taking up CPU time (more than 7 seconds be default), Windows will stop calling it without notifying the process (stopping your hotkeys from working). By increasing its priority, AHK has to compete with fewer other processes. Since it doesn't require much CPU time, the remainder will still get assigned to processes it was competing with.

Making any other demanding process high priority would achieve the opposite result and essentially put all AHK processes in a time-out corner while Windows is waiting for a responce.
brutus_skywalker
Posts: 175
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: detect unresponsive scripts

24 Dec 2016, 14:32

The simplest solution is usually the most elegant one,
add logging to file functionality to the scripts u wish to monitor, and create a new helper script with the single job of checking how long ago the log files were modified in reference to current time,seconds minutes- ur pick,if a script hasn't modified the logs in a bit,it's probably hung so terminate and restart it
... If running as a script use IfInString command to dtermine which autohotkey process belongs to the hung script by searching for the ahk instance with command line params containing hung script name as a string. vualla. use it's pid to terminate and restart it, or simpler still force single instance on ya scripts and any time they get hung,just run em again which is a crude reload...
Outsourcing Clicks & Presses Since 2004.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: detect unresponsive scripts

07 Jan 2017, 02:29

Doing tests on unresponsive scripts.
They all seem to be the same kind of 'unresponsive',
everything is working except that all the hotkeys/hotstrings have failed.

The problems are then:
- No sure method to reset all hotkeys/hotstrings.
- The 'Could not close the previous instance of this script. Keep waiting?'
message. Ideally you would state: give the script n seconds to reload,
if it still exists, terminate and reopen, and NO MSGBOX.
- Why is it sometimes that scripts are slow to reload or incapable of reloading?

Workarounds to consider are then:
- Can the Hotkey command or some other method refresh all hotkeys/hotstrings?
- Can the 'Could not close...' MsgBox be made into a hidden window?
(A script can see that the hidden MsgBox exists and thus terminate and reopen the script.)
- Are there methods to make the 'Could not close...' MsgBox less likely,
such as increasing the priority of that process,
decreasing the priorities of other processes,
and reloading scripts one at a time (rather than all at the same time)?
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: detect unresponsive scripts

10 Jan 2017, 23:15

What I want to do is this:
Add an obscure hotkey like '^#!Pause::'
to my main 8 scripts that use hotkeys.
The hotkey would trigger a PostMessage or a FileAppend,
and would confirm the hotkeys were still working.
If no confirmation is received,
the script would be set to high priority, and a reload triggered.

The problems are to send a hotkey used by multiple scripts,
to a specific script, and that sometimes set priority seems to fail,
even though the scripts are not RunAsAdmin,
and can be prioritised via Task Manager.

[EDIT:]
AutoHotkey's 'Process, Priority' subcommand, and the dll function SetPriorityClass,
are working on Windows 7 as usual. I fixed the issues with my scripts.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], robinson and 158 guests