Help with threading

Tom wright thomas.wright1 at ntlworld.REMOVETHIS.com
Thu Oct 19 07:50:57 EDT 2000


Hi All,

sorry if this is a newbie problem, but i have RTFM etc

I have a problem with the following class

from threading import *

class KernelThread(Thread):
    "A Kernel Thread implementation"

    def __init__(self):
        # init the base class constructor
        Thread.__init__()
        # set the thread to a daemon thread
        self.setDaemon( TRUE )
        # create the event we sleep on
        self.sleepingEvent = Event()
        # start the thread
        self.start();

    def run(self):
        # the main thread event loop
        while(1):
            wait( self.sleepingEvent )
            self.targetObject.handleMessage( self.internalMessage )
            self.sleepingEvent.clear()
            del self.targetObject
            del self.internalMessage

    def handleMessage(self,message,destObject):
        # set up the data for the thread to handle
        self.internalMessage = message
        self.targetObject = destObject
        self.sleepingEvent.set()

when i try and create an instance of the class i get

>>> t = KernelThread()
Traceback (innermost last):
  File "<pyshell#36>", line 1, in ?
    t = KernelThread()
TypeError: call of non-function (type module)

As i am a newbie to Python ( but not programming ), i seem to be missing
something to do with threading/python syntax here.  Any help REALLY
appreciated, i am sure its an obvious omission on my part so dont flame me
to hard :-)

Regards

Tom Wright





More information about the Python-list mailing list