Re: [pygtk] shutting down worker threads

2006-03-29 Thread Jason Pepas
On Wednesday 29 March 2006 12:21 pm, you wrote:
 Jason Pepas napisaƂ(a):
  When I want to stop my program, how do I interrupt what the worker
  threads are doing to tell them it is time to stop?

 You can poll shared object for stop flag in worker thread (in
 something like timer object). And besides that, you have no other
 options in Python.

Damn, I was hoping to be able to use interruption instead of polling.  Oh 
well...

-jason
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] shutting down worker threads

2006-03-28 Thread Jason Pepas
Hi guys,

I have been wrapping my brain around the idea of getting asynchronous gui 
updates with worker threads working, and I have covered all but the last 
step.

When I want to stop my program, how do I interrupt what the worker threads are 
doing to tell them it is time to stop?

I have attached a simple example which demonstrates what I am working on.  Try 
hitting the thread button a bunch of times and them closing the window.

Thanks,
Jason Pepas
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] shutting down worker threads

2006-03-28 Thread Brian
On Tue, 2006-28-03 at 14:38 -0600, Jason Pepas wrote:
 Hi guys,
 
 I have been wrapping my brain around the idea of getting asynchronous gui 
 updates with worker threads working, and I have covered all but the last 
 step.
 
 When I want to stop my program, how do I interrupt what the worker threads 
 are 
 doing to tell them it is time to stop?
 
 I have attached a simple example which demonstrates what I am working on.  
 Try 
 hitting the thread button a bunch of times and them closing the window.
 
 Thanks,
 Jason Pepas

Here are some code snipits we use for shutting down threads.

class CommonWorker(threading.Thread):
 Common threading class
def __init__( self ):
 Initialize 
threading.Thread.__init__(self)
# for keeping status
self.count = 0
# we aren't done yet
self.done = False
# cancelled will be set when the thread should stop
self.cancelled = False
# quit even if thread is still running
self.setDaemon(1)

def please_die( self ):
 Tell the thread to die and is safe to call from other threads 
self.cancelled = True

class UpgradableListReader(CommonWorker):
 Read available upgrades and store them in a tuple 
def __init__( self, installed, upgrade_only, view_prefs ):
 Initialize 
CommonReader.__init__(self)
# [snip]

def run( self ):
fill upgrade tree
#[snip]

# in appropriate places such as loops add this line
if self.cancelled: self.done = True; return


from the main thread:

self.up_thread = UpgradableListReader(installed_list, 
upgrade_only_flag, preferences)
...
self.up_thread.please_die()
-- 
Brian [EMAIL PROTECTED]

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] shutting down worker threads

2006-03-28 Thread Brian
On Tue, 2006-28-03 at 18:10 -0800, Brian wrote:

 CommonReader.__init__(self)
 # [snip]

In case you didn't notice: It should be:

CommonWorker.__init__(self)

That's what I get for trying to change things in snipits.
-- 
Brian [EMAIL PROTECTED]

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/