Forum Archive

Background execution

ihf

Is it still the case that it is NOT possible to keep a pythonista script (that is waiting for data on a socket) running in the background (app not on screen or screen off)? I recall that there was a way to keep a script running for a short time before IOS would terminate it but I want something that runs persistently in the background waiting for a TCP event.

omz

This is not possible for technical reasons. It‘s just not allowed by Apple, though you could keep the app open while using another one on an iPad (using split screen).

JonB

out of curiosity, how does the new python keyboard work? does it spawn a new interpreter each time the keyboard is shown?

On a related topic, @omz, I wonder if you might consider a system to hook custom scripts into widgetPerformUpdateWithCompletionHandler? IIRC that was some a method that get called periodically in the background...

isaingard
@ui.in_background
def button_tapped(sender):
    alert_result = console.alert('Title', 'Message', 'Button 1', 'Button 2')
    sender.title = 'Button ' + str(alert_result)

This is in the documentation for the ui module. Not sure if this is what you are looking for, but it will run the function on a background thread instead of the regular interpreter thread.