mainthread

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()