background

Run code in background indefinitely

This module allows you to keep running a script in the background indefinitely. A great usage of this is fetching data in background and sending notifications with notifications. You can also run a server or a Discord bot for example.

Note: Because of privacy, apps cannot access to the clipboard in background, so coding a clipboard manager is not possible.

class background.BackgroundTask(audio_path=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
notification_delay

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
reminder_notifications

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 False to 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.

wait(delay: float)

Waits n seconds. Does the same thing as time.sleep.

Parameters:delay – Seconds to wait.