[PyKDE] exec_loop blocking problem under Windows

Tuvi, Selim stuvi at SLAC.Stanford.EDU
Fri Jun 21 23:37:01 BST 2002

Thanks for clearing that up a little. Here is what I tried modifying the PyQt version of the aclock.py example:

#!/usr/bin/env python

import sys
from qt import *
import thread

def event_loop_thread():
  global a

def start_event_loop():
rest of the aclock code

a = QApplication(sys.argv)
clock = AnalogClock()
while 1:
  print "In while loop"

So I hoped that the main python interpreter thread and the "event_loop_thread" would run asynchronously.
When I run this I do get the print statement every three seconds but the clock window doesn't respond to any events (the mouse pointer turns into an hourglass and I can not move the window. Maybe I am not doing this right. Any ideas?


-----Original Message-----
From: Green, Gregory P [mailto:gregory.p.green at boeing.com] 
Sent: Friday, June 21, 2002 2:19 PM
To: Tuvi, Selim
Cc: 'pykde at mats.gmd.de'
Subject: RE: [PyKDE] exec_loop blocking problem under Windows

This behaviour is common to all gui libraries, not just PyQt. It is called "event driven programming". The main gui will just loop, waiting for events to arrive and then processing them. Most libraries have an "idle event" which will be executed whenever no other events are waiting. If your task can be broken down into little chunks that can be processed at random times, you can do it this way. More commonly, another thread or process is used to do the processing which then communicates via some IPC mechanism with the gui thread/process. In python using threads and the Queue module is a good way to do this. But there are many other ways. So the short answer to your question, is yes you can do what you are asking, using any version of PyQt, python, and OS. It may or may not be the best way to do it. If you provide more information, then we can give a better answer.

-----Original Message-----
From: Tuvi, Selim [mailto:stuvi at SLAC.Stanford.EDU]
Sent: Friday, June 21, 2002 2:02 PM
To: 'pykde at mats.gmd.de'
Subject: [PyKDE] exec_loop blocking problem under Windows

Hi all, I am new to Python, QT and PyQt so bear with me please.

I noticed that when running a script when exec_loop is executed the Python interpreter blocks (ie. doesn't execute the subsequent commands). Is this the default behaviour on all platforms or is it something specific to Windows?

What I'd like to have is run exec_loop in a python thread and do other processing in my script? Is this possible with the current PyQt release? We are currently using QT 3.0.4 and Python 2.2.1 under Windows 2000.

More information about the PyQt mailing list