Re: Threading problem in cli_python

Lalo Martins <[email protected]> Sun, 4 May 2003 15:13:10 -0300
Newsgroups gmane.comp.video.picogui.devel
Message-ID <[email protected]>
On Wed, Apr 30, 2003 at 09:27:55PM -0500, Carpman wrote:
> I've noticed that cli_python seems basically thread intolerant. For example...
> 
> def threadA():
>    app.run()
> 
> t = threading.Thread(None,
> 				   threadA,
> 				   None)
> t.start()
> app.addWidget(...) 
> 
> Fails to add a widget. It just hangs at addWidget. 

Ok, I added a file sample/thread_test.py which is basically what
you have above, with some side dishes.

Turns out it's worse than that :-( seems to be a race
condition.  Most of the time the "app" works as expected, but

1. sometimes it does as you say; the debugging spewage says the
run() thread was the last one to acquire the lock.  In this
case, the label does appear when the lock is released (to see
that happening, click the button; it makes pgserver return an
event, which in turn releases the lock).

I would expect that to be the usual case; the short answer is,
finish your app's setup before you start run().

2. sometimes, however, both threads acquire the lock at the same
time - this seems to be a bug in python's thread module, I will
check if it is known.  This results in a deadlock and I have to
kill -9 :-(

Oddly enough, trying this in python2.3a1 *never* works correctly.

I think the lesson to be learned is, always setup everything
*before* starting the threads.

That said, in pdaNifty I have some code where an app is running
in one thread and another thread writes stuff to a popup... I
don't know what I'm doing differently, but it works.

[]s,
                                               |alo
                                               +----
--
            Those who trade freedom for security
               lose both and deserve neither.
--
http://www.laranja.org/                mailto:[email protected]
         pgp key: http://www.laranja.org/pessoal/pgp

Eu jogo RPG! (I play RPG)         http://www.eujogorpg.com.br/
GNU: never give up freedom                 http://www.gnu.org/


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf