is this a question or an answer? is this a cocoa question or a PyObjC
question?
On 6/6/07, Tom Elliott <[EMAIL PROTECTED]> wrote:
The kill() method is just a stub, written back when I thought the way to
do this is for the main thread to terminate the worker thread. Now, after
more reading, I realize it's better to have the worker test a condition
periodically and exit (gracefully) if necessary.
The withObject_ parameter can be used to pass a reference back to the
original thread. This is useful when the new thread executes a method in a
different class. I ended up just calling a method in the same class, like
this:
from Foundation import *
from AppKit import *
import objc, time
from PyObjCTools import NibClassBuilder
class PyThreadAppDelegate(NibClassBuilder.AutoBaseClass):
def init(self):
self = super(PyThreadAppDelegate, self).init()
return self
def go_(self, sender):
print 'go_'
self.continueFlag = True
#t = Threaded.alloc().init()
NSThread.detachNewThreadSelector_toTarget_withObject_(
'newThread:', self, None)
def kill_(self, sender):
print 'kill_'
self.continueFlag = False
@objc.signature('v:@')
def newThread_(sender):
pool = NSAutoreleasePool.alloc().init()
print 'Threaded', sender
for i in range(10):
if sender.continueFlag:
time.sleep(1)
print i
del pool
Thanks.
_______________________________________________
Pythonmac-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/pythonmac-sig
--
"lalalalala! it's not broken because I can use it"
http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703
_______________________________________________
Pythonmac-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/pythonmac-sig