What are the best approaches to having a responsive UI which also allows background threads to run relatively smoothly in Pythonista apps?
More specifically, I'm having trouble in a setup where a user interacts with a custom widget, one where they touch and drag around on it to send messages. I was hoping to have those messages placed into a thread-safe queue and then be processed by a thread running separately from the main/ui threads.
For me, using either the Gestures module, or the touch_began(), touch_moved() and touch_ended() methods of a custom view, the consumer thread which processes the messages very rarely gets a chance to run. Even if I put in time.sleep(0) calls after each time the touch interaction places a message on the queue, trying to force the main thread to release control, I find the background thread seldom gets any time to process...if I pause while interacting, drag around for a moment and then stop, the background thread suddenly gets a chance to process all the queued up messages. But while dragging, almost never.
So, is this just the GIL being it's problematic self? Is there a particular design-pattern which works very well for this scenario, and allows the user to interact relatively smoothly while still letting a background thread perform tasks? Is there some use of in_background(), or the objc_util on_main_thread() which would make this work better?
I'm not married to the threaded system I'm using, if there's a really good asynchronous or semi-asynchronous way of doing things. This is in Python2.7, by the way...so asyncio is not available, and since it's iOS there's no option to use multiprocessing.