Controlling threads

I have a CLI python program for which I'm writing GUI. The program takes a
number of files and filters them.

def OnStartButtonClick(self, event):
        w = Worker(directory)
        w.start()

I'd like to have the worker in a background thread so that GUI keeps
responding to events, and even more important, to have STOP button (which
will, I presume, put some kind of stopper object in some kind of queue,
which that background thread should check periodically.)

I'm very new to Python and I don't know how to implement that. The
following url explains some details but I wasn't able to incorporate it in
my program:

http://www.python.org/cgi-bin/moinmoin/ThreadProgramming

GUI still doesn't respond.

My Worker object is single-threaded (it takes one file after another).
Maybe I should rewrite it to something like

for file in directoryList:
        w = Worker(file)
        w.start()

and basically have new Worker for each file.

Also, it is important that I should be able to stop the processing of a
single file at any given time, even in the middle of the process.

So, after all these requests, is there any good examples which I could use?
I already read the Threads example in the demo collection, but to be
honest, I really don't understand it :slight_smile:

Thanks in advance!

Regards,
Davor

···

--
davor.cengija@mail.inet.hr

Try this:
http://wiki.wxpython.org/index.cgi/LongRunningTasks

···

On Sunday 23 March 2003 08:09 am, Davor Cengija wrote:

So, after all these requests, is there any good examples which I
could use? I already read the Threads example in the demo collection,
but to be honest, I really don't understand it :slight_smile:

--
Chuck
http://ChuckEsterbrook.com

Threading is not really a wxPython specific topic.

However, in wxPython, additional threads should not interact directly with the gui, leave that job to the main thread! (where have I hard that before)

I have developed a threaded routine (because I'm experimenting, etc...) you can find the source in my project

http://recon.sourceforge.com

The module threaded_getstatus.py encapsulates 2 intertwined classes which deal with threads and signal events to wx. It is also in the latest package release. It may not be the most elegant example, but should help. Since recon uses wxPython, it might help with wxPython interaction as well.

Heh, I used threads because of the default blocking operation of socket io... argh... I've since discovered the modules asyncore and select (various documentation reffered to poll() but that's burried in select module (which I was guessing was sql somehow), which I didn't find until after threads) DOH, now I'm really off topic... But I'm still learning!!! :slight_smile:

-Joe

Davor Cengija wrote:

···

I have a CLI python program for which I'm writing GUI. The program takes a number of files and filters them.

def OnStartButtonClick(self, event):
       w = Worker(directory)
       w.start()

I'd like to have the worker in a background thread so that GUI keeps responding to events, and even more important, to have STOP button (which will, I presume, put some kind of stopper object in some kind of queue, which that background thread should check periodically.)

I'm very new to Python and I don't know how to implement that. The following url explains some details but I wasn't able to incorporate it in my program:

FrontPage - Python Wiki

GUI still doesn't respond.

My Worker object is single-threaded (it takes one file after another). Maybe I should rewrite it to something like

for file in directoryList:
       w = Worker(file)
       w.start()

and basically have new Worker for each file.

Also, it is important that I should be able to stop the processing of a single file at any given time, even in the middle of the process.

So, after all these requests, is there any good examples which I could use? I already read the Threads example in the demo collection, but to be honest, I really don't understand it :slight_smile:

Thanks in advance!

Regards,
Davor

Chuck Esterbrook wrote:

···

On Sunday 23 March 2003 08:09 am, Davor Cengija wrote:

So, after all these requests, is there any good examples which I
could use? I already read the Threads example in the demo collection,
but to be honest, I really don't understand it :slight_smile:

Try this:
http://wiki.wxpython.org/index.cgi/LongRunningTasks

This looks very much as the solution for the type of problems I described.
Thanks, I'll try it and report my findings.

Regards,
Davor
--
davor.cengija@mail.inet.hr