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

T

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
 
B

Bjoern Schliessmann

Tor said:
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
 
C

Cliff Wells

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

--
 
L

Lawrence Oluyede

Tor Erik said:
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.
 
T

Tor Erik

Bjoern said:
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
 
P

Paul Rubin

Tor Erik said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top