auto-selfcontrol icon indicating copy to clipboard operation
auto-selfcontrol copied to clipboard

Failing to start block when waking from sleep

Open gcohara opened this issue 5 years ago • 0 comments

Hi,

Upon waking the computer, often the block fails to start. This occurs when the computer went to sleep during a previous block - for instance, if the computer went to sleep during a block from 9pm to 7am, and is then woken during a block from 9am to 6pm. Looking at the syslog, I found the following:

Aug 13 10:46:45 georges-mbp Auto-SelfControl: 
[ERROR] SelfControl is already running, ignore current execution of Auto-SelfControl.

Aug 13 10:46:45 georges-mbp com.apple.xpc.launchd[1] (com.parrot-bytes.auto-selfcontrol[73333]): 
Service exited with abnormal code: 2

It seems that upon wakeup the auto-selfcontrol script is run before the SelfControl daemon has a chance to clear itself.

It doesn't seem that the macOS launchctl utility has many options for starting daemons at a delay after wakeup etc, so I went for the simple solution of putting

time.sleep(1)

in the main function for the script. This should hopefully give the SelfControl daemon time to remove itself.

Possibly you might want a more elegant solution, but if it works I'll submit a PR anyway.

gcohara avatar Aug 13 '20 13:08 gcohara