Simple threading thing

Thomas Weholt thomas at gatsoft.no
Fri Mar 1 02:55:18 EST 2002


I was calling the maintanence-thread's run()-method, not its start()-method.
Thanks to Cliff Wells for helping me with that.

Here's the code in question for later use :

import time, threading

class MyThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        while 1:
            time.sleep(10)
            print "Doing something"

class t:
    def __init__(self):
        self.worker = MyThread()
    def serve(self):
        self.worker.start() # was self.worker.run()
        while 1:
            time.sleep(5)
            print "Main class serving ..."

x = t()
x.serve()


Now it works just great! Thanks for all your help, interest and input.

Best regards,
Thomas Weholt

"Martin v. Loewis" <martin at v.loewis.de> wrote in message
news:m3u1s19qhu.fsf at mira.informatik.hu-berlin.de...
> "Thomas Weholt" <thomas at weholt.org> writes:
>
> > I need a thread, no forking. Should run in Linux and Win32. I need a
thread
> > that functions in the background, running beside the main server, with a
> > reference to the main server so it can maintain states etc. in it. The
> > purpose of the process is to mainly remove expired sessions ( remember
this
> > is a webserver ), log certain values and monitor the server, and work as
> > sort of a janitor.
> >
> > Does that make it any clearer?
>
> Not really. The main process starts. What happens next? I interpret
> your posting as
>
> - creates a new thread, to observe the main thread
> - the main thread should continue to run, but doesn't
>
> Is that correct? How do you know it does not run?
>
> If this are all the fact, it is really hard to believe. There must be
> details that you've omitted.
>
> Regards,
> Martin





More information about the Python-list mailing list