Re: Why not event-driven packages in other than the main thread?

2006-09-15 Thread Paul Rubin
Tor Erik <[EMAIL PROTECTED]> writes:
> I've developed an application were I've used Tkinter for the GUI.
> When I ran the GUI in another thread than the main, it kept locking
> up.  I experienced similar problems with Twisted.

Tkinter is not thread-safe.  You have to synchronize any cross-thread
communication with it.  The way I usually do it is with an "after"
method that checks a communications queue (Queue.Queue object) every
20 msec or so.  Any communication to and from the gui thread is done
through the queue.  There is a recipe like this in the Python Cookbook
and you can probably find it at ASPN.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Lawrence Oluyede
Bjoern Schliessmann <[EMAIL PROTECTED]>
wrote:
> What's not real about Tkinter's?

It's not a custom reactor as GTK's AFAIK

-- 
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Bjoern Schliessmann
Lawrence Oluyede wrote:

> It's better to use GUI with a real reactor available like GTK2
> anyway...

What's not real about Tkinter's?

Regards,


Björn 

-- 
BOFH excuse #371:

Incorrectly configured static routes on the corerouters.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Tor Erik
Jean-Paul Calderone wrote:
> On Thu, 14 Sep 2006 11:13:59 +0200, Tor Erik <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I've developed an application were I've used Tkinter for the GUI.
>> When I ran the GUI in another thread than the main, it kept locking
>> up.
>> I experienced similar problems with Twisted.
>>
>> Both of these tools are event-based, so I guess that is the root of the
>> problem...
>>
>> But could anyone tell me why running these in a thread other than the
>> main one doesn't work?
> 
> I don't know about Tkinter, but Twisted can be run in a thread other than
> the main thread.  Several projects make use of this feature extensively, so
> while I wouldn't recommend it, it should certainly work.
> 
> Perhaps you did something wrong in setting it up, or perhaps you have found
> a bug.  Can you post a minimal example to reproduce this to Twisted's bug
> tracker?
> 
> Jean-Paul

Oh... I've re-coded that part of my app. now, so it doesn't contain any 
references to Twisted anymore. However, I was aiming to build a scalable 
HTTP server, and tried using Twisted for the task. Whenever I started 
the thing from the main thread (as a separate thread), nothing happened. 
That is, I received no exceptions, but the HTTP server was not 
running... When executing the HTTP server as a separate app., things 
worked perfectly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Jean-Paul Calderone
On Thu, 14 Sep 2006 11:13:59 +0200, Tor Erik <[EMAIL PROTECTED]> wrote:
>Hi,
>
>I've developed an application were I've used Tkinter for the GUI.
>When I ran the GUI in another thread than the main, it kept locking
>up.
>I experienced similar problems with Twisted.
>
>Both of these tools are event-based, so I guess that is the root of the
>problem...
>
>But could anyone tell me why running these in a thread other than the
>main one doesn't work?

I don't know about Tkinter, but Twisted can be run in a thread other than
the main thread.  Several projects make use of this feature extensively, so
while I wouldn't recommend it, it should certainly work.

Perhaps you did something wrong in setting it up, or perhaps you have found
a bug.  Can you post a minimal example to reproduce this to Twisted's bug
tracker?

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Lawrence Oluyede
Tor Erik <[EMAIL PROTECTED]> wrote:
> If you have two event-based frameworks, both needing to run in the main
> thread, such as Tkinter and Twisted, you have a problem

Twisted supports Tkinter:
http://twistedmatrix.com/projects/core/documentation/howto/choosing-reac
tor.html#auto14

It's better to use GUI with a real reactor available like GTK2 anyway...

-- 
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Tor Erik
Bjoern Schliessmann wrote:
> Tor Erik wrote:
> 
>> But could anyone tell me why running these in a thread other than
>> the main one doesn't work?
> 
> Just for personal interest: Why would you want to run the GUI in
> another thread? It's common to leave the GUI in the main thread and
> let worker threads handle heavy time-consuming stuff.
> 
> Regards,
> 
> 
> Björn
> 

If you have two event-based frameworks, both needing to run in the main 
thread, such as Tkinter and Twisted, you have a problem
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Lawrence Oluyede
Tor Erik <[EMAIL PROTECTED]> wrote:
> I've developed an application were I've used Tkinter for the GUI.
> When I ran the GUI in another thread than the main, it kept locking
> up.

That's because Tkinter is not thread safe AFAIK.

> I experienced similar problems with Twisted.

Neither Twisted is thread-aware. It uses thread for a couple of things
(twisted.row and address resolution). You can call stuff in a separate
thread with deferToThread or callInThread but avoid threads is best. 

> But could anyone tell me why running these in a thread other than the
> main one doesn't work?

Because neither Twisted nor Tkinter are meant to work with threads.

-- 
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Cliff Wells
On Thu, 2006-09-14 at 03:22 -0700, Cliff Wells wrote:

> They probably use signals (Twisted I'm sure does) and it's documented
> that signals don't work with threads:
> 
> http://docs.python.org/lib/module-signal.html


Er, specifically, they only work with the main thread.

Cliff
-- 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Cliff Wells
On Thu, 2006-09-14 at 11:13 +0200, Tor Erik wrote:
> Hi,
> 
> I've developed an application were I've used Tkinter for the GUI.
> When I ran the GUI in another thread than the main, it kept locking
> up.
> I experienced similar problems with Twisted.
> 
> Both of these tools are event-based, so I guess that is the root of the 
> problem...
> 
> But could anyone tell me why running these in a thread other than the 
> main one doesn't work?

They probably use signals (Twisted I'm sure does) and it's documented
that signals don't work with threads:

http://docs.python.org/lib/module-signal.html

Regards,
Cliff

-- 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why not event-driven packages in other than the main thread?

2006-09-14 Thread Bjoern Schliessmann
Tor Erik wrote:

> But could anyone tell me why running these in a thread other than
> the main one doesn't work?

Just for personal interest: Why would you want to run the GUI in
another thread? It's common to leave the GUI in the main thread and
let worker threads handle heavy time-consuming stuff.

Regards,


Björn

-- 
BOFH excuse #170:

popper unable to process jumbo kernel

-- 
http://mail.python.org/mailman/listinfo/python-list


Why not event-driven packages in other than the main thread?

2006-09-14 Thread Tor Erik
Hi,

I've developed an application were I've used Tkinter for the GUI.
When I ran the GUI in another thread than the main, it kept locking
up.
I experienced similar problems with Twisted.

Both of these tools are event-based, so I guess that is the root of the 
problem...

But could anyone tell me why running these in a thread other than the 
main one doesn't work?

regards
-- 
http://mail.python.org/mailman/listinfo/python-list