Forum Archive

Background timer

ihf

Is there a way to create an alarm/timer which will run in the background? I see that the alarm method is not in the signal module but I wondered if there was a way to do this.

henryiii

You can schedule a notification.

import notification
notification.schedule('2 minutes have passed',120)
ihf

Thanks, that helps. Just curious, do you know if the absence of the alarm method is due to the sandboxing (although other apps can implement alarms) or some other reason?

JonB

A notification IS an alarm. You can set the time, and a sound to play, and and action to take when the user hits ok. That action can be another pythonista script using the pythonista url format.

ihf

Thanks, I understand that I can change existing scripts that use signal.alarm. I was just wondering whether the deletion of the signal.alarm method is a result of some undesired effect (from Apple's POV) or some other reason.

ccc

Ahhh... You are talking about the Python Standard Library module https://docs.python.org/2/library/signal.html

ihf

Exactly. As also found in the Pythonista docs: http://omz-software.com/pythonista/docs/library/signal.html

ccc

I believe that only OMZ can tell us why there is no signal.alarm() function. But notification.schedule is a reasonable iOS-specific substitute.