开发者

Python thread is not breaking from parrent thread

Question: why is my DAL not running off on its own thread?


I've got this program I've been working on that I implemented a simple file manager back end on. This is far from my first experience working with threads, but for some reason I just can't get this one working. I instantiate my DAL here:

    self.DAL = DAL(path)
    ##prepare the reactor
    self.DALrec = threading.Thread(target=self.DAL.reactor,name='DALReactor')
    self.DALrec.run()

The reactor has this in it:

    def reactor(self):
        while not self.kill:
            ##check for new entries:
            for i in self.ins:
                self.save(i)

            ##wait a minute before checking again.
            time.sleep(60)

Not complicated. I instantiate the DAL which goes down with out a hitch and then instantiate a thread, just like I've always done. But for some reason I'm getting a really bazaar behavior out of this. Instead of calling 'run' and the main thread continuing on leaving the thread to its own business, it is treating 'run' as if I was calling self.DAL.reactor() from the main thread. In my debugger (winpdb, which worked on my previous version of this program) I should be seeing a new thread being created, but there remains only one thread.

Anyone have any idea w开发者_如何学编程hy I only have one thread here instead of two? Thanks.


You should call start, to run the run method in a separate thread. Otherwise run is called as any other method.

From docs: Once a thread object is created, its activity must be started by calling the thread’s start() method. This invokes the run() method in a separate thread of control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜