Forum Archive

Running in background / preventing auto-lock?

iisdev

I apologize in advance - this is probably another basic question.

I'd like my python program to run continuously in the background until:

  1. it completes it's processing or
  2. I tell it to stop.

What tends to happen now is that (when it's working on a larger batch) the lock screen automatically kicks in after a couple of minutes and the script just dies. Is there an iOS-related command I can call (on a script-by-script basis) that would prevent it from doing this without having to disable 'Auto-Lock' manually in the iOS settings?

I noticed that some iOS games remain running (even after 5 minutes with no user input). This is what I'm trying to do. I'm not worried about draining the battery because the device is usually plugged in and charging and having that second screen to monitor while I work on something else would be really helpful.

Thank you again for Pythonista!

omz

You can use console.set_idle_timer_disabled(True) for this (set it to False again when you're done with your long-running activity).

iisdev

Ok great - thank you!

Snaresman

When I add this line, the app kicks me back to the home screen every time and the program doesn’t start. Why is that?

cvp

@Snaresman see here

mikael

@Snaresman, the link took me on a bit of a run-around, so here’s the workaround for the bug:

import console
from objc_util import on_main_thread

on_main_thread(console.set_idle_timer_disabled)(flag)
Samuels

I wrote a little utility that runs in your system tray and prevents your computer from locking or going into screensaver mode as it normally would when idle and while it is not really Symantec related, I have found it very useful and I thought I would share it UPSers