Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Threads with Python in Desktop

Does Titanium Desktop support threads at all that can access the GUI? For example, I have a python program that I want to be able to update when it receives notifications. I can't seem to get it to work as it either stalls if I use a standard loop or if I spawn a thread it seems to not update the GUI.

Any ideas/thoughts?

Thanks!

-rob

— asked August 17th 2010 by Rob Scheibel
  • python
  • thread
0 Comments

2 Answers

  • Got it figured out and thought I'd share with others in similar situations!

    WebKit is not thread safe, so python threads can not update the GUI/DOM. What you can do though is create some python functions and call them using Titanium.API.runOnMainThread(function, …) from your threads passing in the information you want to propagate to the GUI/DOM and it will update it for you on the main thread.

    Works pretty slick and keep your app working great!

    Hope it helps others!

    -rob

    — answered August 19th 2010 by Rob Scheibel
    permalink
    1 Comment
    • Can you please provide an example?

      — commented May 5th 2011 by Susana Ferreira
  • Thanks, this worked great for me.

    A note, in the new version of appcelerator. Calling the javascript function name doesn't work. You have to do window.function_name. Everything worked for me once I did thi.

    — answered November 17th 2011 by Ray Wang
    permalink
    3 Comments
    • Dang, I was really hoping this would be the answer to my question. But so far, it's not. I'm calling a js function from within a python function, and it simply does nothing (except prevent the js from executing). I need to find out how do debug.

      — commented January 24th 2012 by Murphy Randle
    • Wait a minute, that DID help, but I'm wondering how to call a Java function with parameters now. Because that isn't working.

      — commented January 24th 2012 by Murphy Randle
    • Zoink that. It didn't, I was mistaken. Where's the edit button?

      — commented January 24th 2012 by Murphy Randle
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.