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 that makes a function run in synchronously on 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.
mainthread.run_sync(code)

Runs the given code asynchronously on the main thread. Supports return values as opposed to run_async()

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