mainthread

Access the main thread

This module allows you to run code on the main thread easely. This can be used for modifiying the UI.

Example:

from UIKit import UIScreen
import mainthread

def set_brightness():
    inverted = int(not int(UIScreen.mainScreen.brightness))
    UIScreen.mainScreen.setBrightness(inverted)

mainthread.run_async(set_brightness)
mainthread.mainthread(func)

A decorator for a function running in the main thread.

Example:

import mainthread
from UIKit import UIApplication

@mainthread.mainthread
def run_in_background():
    app = UIApplication.sharedApplication
    app.beginBackgroundTaskWithExpirationHandler(None)

run_in_background()
mainthread.run_async(code)

Runs the given code asynchronously on the main thread.

Parameters:code – Code to execute in the main thread.