BackgroundTask¶
- class background.BackgroundTask(audio_path: str = None, id: str = None)¶
Represents a task to run in background. When started, the audio at the path passed to the initializer is played. If no audio is passed, a blank audio is used so Pyto isn’t killed by the system.
Usage:
import background as bg with bg.BackgroundTask() as b: while True: print(b.execution_time()) b.wait(1)
- execution_time() int¶
Returns the total execution time of the task in seconds.
- Return type:
int
- id: str = None¶
A string that identifies the task. If a task with the same ID of a task that is already running is started, the other task will be stopped. That is useful with Shortcuts Personal Automations where you can create a background task multiple times to make sure it’s running without having to worry about the task already running.
- property notification_delay: int¶
The delay in seconds since each reminder notification. If set to 3600, a notification will be sent every hour while the task is running. The default value is
21600(6 hours).- Return type:
int
- property reminder_notifications: bool¶
A boolean indicating whether a notification should be sent while the task is running. By default, a notification is sent every 6 hours while the task is running, set this property to
Falseto disable that,- Return type:
bool
- start()¶
Starts the background task. After calling this function, Pyto will not be killed by the system.
- stop()¶
Stops the background task. After calling this function, Pyto can be killed by the system to free memory (if no other task is running).
- wait(delay: float)¶
Waits n seconds. Does the same thing as
time.sleep.- Parameters:
delay – Seconds to wait.