Stop watching HID

I get this in my Engine.log file a lot: (notice the time between stop and start ranges from one second to 4 minutes. When the difference is one second, I don't notice any problems, but when the difference is four minutes, the KM engine is non-responsive to my keys. Until when? Until I open the KM degubber, then it seems to restart.)

2019-09-14 16:23:51 Stop Watching HID Devices
2019-09-14 16:24:07 Start Watching HID Devices
2019-09-14 16:24:16 Stop Watching HID Devices
2019-09-14 16:24:17 Start Watching HID Devices
2019-09-14 16:24:33 Stop Watching HID Devices
2019-09-14 16:28:21 Start Watching HID Devices
2019-09-14 16:28:47 Stop Watching HID Devices
2019-09-14 16:29:57 Start Watching HID Devices
2019-09-14 16:37:17 Stop Watching HID Devices
2019-09-14 16:38:33 Start Watching HID Devices
2019-09-14 16:41:28 Stop Watching HID Devices
2019-09-14 16:43:33 Start Watching HID Devices
2019-09-14 16:50:09 Stop Watching HID Devices
2019-09-14 16:50:28 Start Watching HID Devices
2019-09-14 16:50:38 Stop Watching HID Devices
2019-09-14 16:51:01 Start Watching HID Devices
2019-09-14 16:51:10 Stop Watching HID Devices
2019-09-14 16:51:26 Start Watching HID Devices
2019-09-14 16:52:17 Stop Watching HID Devices
2019-09-14 16:52:44 Start Watching HID Devices
2019-09-14 16:52:57 Stop Watching HID Devices
2019-09-14 16:53:18 Start Watching HID Devices
2019-09-14 16:57:48 Stop Watching HID Devices
2019-09-14 17:01:34 Start Watching HID Devices
2019-09-14 17:01:51 Stop Watching HID Devices

When this happens, basically the KM engine appears as if it's dead, because it doesn't seem to trigger based on any keyboard or other USB device. But the Engine still works for macros that are triggered from other things, like timers.

The first thing I do when I notice this happening is open the debugger window to see if any macros are running, and whenever I do that, the KM Engine suddenly seems to work again. How is that possible?

One of my macros, which triggers every couple of minutes, uses an Execute Shell Script action which is this one:

image

This action had a frequent tendency to never complete execution (and how could that be? shouldn't it always return?), so what I did was put a timeout on it of three seconds. But that doesn't help either, as the log shows:

2019-09-14 17:02:48 Running application query took a while (3594 us)
2019-09-14 17:02:48 Running application query took a while (4628 us)

I'm not sure if these two errors are related, but they seem to happen at the same general times. My speculation is that when the Execute Shell Script fails, it also causes the Engine to stop watching HID Devices.

How could calling Execute Shell Script once every couple of minutes cause a Mac with 8GB RAM to run out of resources and cause the KM Engine too stop reading HID devices?

A few days ago I showed in another post on this website how putting Execute Shell Script actions in a fast loop can force any macOS system to run out of resources, but how does running one Execute Shell Script action every few minutes also cause it to run out of resources?

Obviously I may be making some wrong conclusions here. I'm open to correction.

Keyboard Maestro will watch the Start Watching HID Devices whenever there is a USB Device Key triggered macro active, and when no macros are active, it will stop watching them.

So the time between them will depend on your macros and macro activation, but they will not affect Keyboard Maestro Engine being responsive unless something else is going on.

Is just a reminder that Appleā€™s crappy NSRunningApplications API is still being horrendously slow in responding to trivial requests (not the time is in us, so in those examples around 0.004 seconds). It has nothing do do with your Sort Results action.

Basically, all of this are random unrelated (or related to some underlying issue) - there is nothing in any of this that I can make any suggestions for resolving.