20 second process?

I created a home control app that, among other things, collects and processes sensor data and then sends the results out via udp once per second. This app has been running successfully for years on Duo based iMacs running pre 10.8, but when I put it on an i5 or i7 iMac running Sierra or later, it runs correctly for about 10 minutes (screen sleep set at 15min), then seems to go into a slow motion mode where it only collects and sends data every 20 seconds. This is with the power settings set for never sleep.

The only way I’ve found to stop that behavior is to call “UpdateSystemActivity” periodically, which of course turns the display back on.

Any idea what’s going on here?

Sounds like the macOS AppNap feature.

You basically have to tell the OS that your app is doing something important in the background otherwise it puts your app to sleep to save energy.

If you have the MBS plugins you can use the NSProcessInfoMBS beginactivity / endActivity methods.

there are open source implementations that do not require mbs available
just not allowed to post a link to it :stuck_out_tongue:

Thanks for the AppNap clue…

“defaults write NSGlobalDomain NSAppSleepDisabled -bool YES” seems to have remedied the issue.

Are you planning on submitting this app to the App Store ?

Nope. Personal use only.