Dismiss Notice
Guest, I have a big favor to ask you. We've been working very hard to establish ourselves on social media. If you like/follow our pages it would be a HUGE help to us. SoSH on Facebook and Inside the Pylon Thanks! Nip

Question for a *SERIOUSLY HARDCORE* Mac programmer

Discussion in 'BYTE ME: Technology discussion' started by glasspusher, Feb 19, 2018.

  1. glasspusher

    glasspusher Member SoSH Member

    Messages:
    9,228
    Figured I'd ask here. Any of my few Mac programmer friends in my area can't answer my question.

    Involves keeping a timer running accurately on a Mac app running in the background. Apple has, over the past few years, become maniacal about saving energy on their laptops, to the point of putting timers to sleep when apps are in the background, and I haven't paid enough attention in the past few years and missed it.

    I have a kludge but would be interested (and impressed!) if anyone knows how to do this the "approved" way.
     
  2. cgori

    cgori Well-Known Member Silver Supporter SoSH Member

    Messages:
    2,098
    Since they are Intel cpus, is this api supported?

    https://www.intel.com/content/dam/w...ations/software-developers-hpet-spec-1-0a.pdf

    (Unfortunately not a Mac developer)
     
  3. EricFeczko

    EricFeczko Member SoSH Member

    Messages:
    2,652
    You could just disable the behavior across all or an individual app:

    http://osxdaily.com/2014/05/13/disable-app-nap-mac-os-x/

    Hope this helps.
     
  4. glasspusher

    glasspusher Member SoSH Member

    Messages:
    9,228
    Thanks- you pass the "seriously hardcore" test. I was looking for something a bit more high level in the OS's APIs. Right now I get things behaving my way by having a daemon ping my app whether it's in the background or not. macOS doesn't throttle daemons.
     
  5. glasspusher

    glasspusher Member SoSH Member

    Messages:
    9,228
  6. EricFeczko

    EricFeczko Member SoSH Member

    Messages:
    2,652
    Bastards...sorry.

    If you're writing in swift, this might help, but knowing you, you're probably already stack-overflowing...

    https://stackoverflow.com/questions/35679066/disable-app-nap
     
  7. SumnerH

    SumnerH Malt Liquor Picker Dope

    Messages:
    25,155
    I think beginActivityWithReasons can be used to disable App Nap, which is what's messing with your timers. Unless things have changed since then (last time I looked at this was a couple years ago).

    https://stackoverflow.com/questions/19847293/disable-app-nap-in-macos-10-9-mavericks-application
     
  8. Blacken

    Blacken Robespierre in a Cape SoSH Member

    Messages:
    11,956
    Sumner has it - beginActivityWithReasons (and, as the SO answer notes, retaining the object so it can't get ARC'd from under you) is the magic bullet here.
     
  9. glasspusher

    glasspusher Member SoSH Member

    Messages:
    9,228
    Thanks, folks, you've been re-tracing my steps (great minds think alike, but fools never disagree). Eventually I made it here, but turns out that's a processor pig. Fuck.
     
  10. glasspusher

    glasspusher Member SoSH Member

    Messages:
    9,228
    I'm pretty sure I tried this one (been about 10 months) but since I'm not so much interested in an activity as a timer to fire consistently, doing this gives me the processor pig thing in Hello, Metronome! above, even from the command line.

    Hello, Metronome! mentioned above is a processor pig in its own right. WTF, Apple?
     
  11. glasspusher

    glasspusher Member SoSH Member

    Messages:
    9,228
    If anyone thinks this a worthy task (whether in the background or not, get it?) to solve without it being an epic, PM me, there may be some compensation I'd give you for your trouble.
     

Share This Page