Esempio n. 1
0
 class TreeComputer(Thread):
     
     rootWord = None;
     newWordEvent = Event();
     keepRunning = True;
     singletonRunning = False;
     
     def __init__(self):
         super(RootWordSubmissionService.TreeComputer, self).__init__();
         if RootWordSubmissionService.TreeComputer.singletonRunning:
             raise RuntimeError("Only one TreeComputer instance may run per process.");
         RootWordSubmissionService.TreeComputer.singletonRunning = True;
     
     def stop(self):
         RootWordSubmissionService.TreeComputer.keepRunning = False;
     
     def run(self):
         self.wordExplorer = WordExplorer(DBPATH);
         while RootWordSubmissionService.TreeComputer.keepRunning:
             RootWordSubmissionService.TreeComputer.newWordEvent.wait();
             newJSONEchoTreeStr = self.wordExplorer.makeJSONTree(self.wordExplorer.makeWordTree(RootWordSubmissionService.TreeComputer.rootWord));
             
             # Store the new tree in the appropriate EchoTreeService class variable:
             with EchoTreeService.currentEchoTreeLock:
                 EchoTreeService.currentEchoTree = newJSONEchoTreeStr;
                 
             # Signal to the new-tree-arrived event pushers that a new
             # jsonTree has arrived, and they should push it to their clients:
             EchoTreeService.notifyInterestedParties();
             RootWordSubmissionService.TreeComputer.newWordEvent.clear();
             EchoTreeService.log(RootWordSubmissionService.TreeComputer.rootWord);
             EchoTreeService.log(newJSONEchoTreeStr);
Esempio n. 2
0
        def run(self):
            self.wordExplorer = WordExplorer(DBPATH)
            while RootWordSubmissionService.TreeComputer.keepRunning:
                RootWordSubmissionService.TreeComputer.newWordEvent.wait()
                newJSONEchoTreeStr = self.wordExplorer.makeJSONTree(
                    self.wordExplorer.makeWordTree(
                        RootWordSubmissionService.TreeComputer.rootWord))

                # Store the new tree in the appropriate EchoTreeService class variable:
                with EchoTreeService.currentEchoTreeLock:
                    EchoTreeService.currentEchoTree = newJSONEchoTreeStr

                # Signal to the new-tree-arrived event pushers that a new
                # jsonTree has arrived, and they should push it to their clients:
                EchoTreeService.notifyInterestedParties()
                RootWordSubmissionService.TreeComputer.newWordEvent.clear()
                EchoTreeService.log(
                    RootWordSubmissionService.TreeComputer.rootWord)
                EchoTreeService.log(newJSONEchoTreeStr)
Esempio n. 3
0
    class TreeComputer(Thread):

        rootWord = None
        newWordEvent = Event()
        keepRunning = True
        singletonRunning = False

        def __init__(self):
            super(RootWordSubmissionService.TreeComputer, self).__init__()
            if RootWordSubmissionService.TreeComputer.singletonRunning:
                raise RuntimeError(
                    "Only one TreeComputer instance may run per process.")
            RootWordSubmissionService.TreeComputer.singletonRunning = True

        def stop(self):
            RootWordSubmissionService.TreeComputer.keepRunning = False

        def run(self):
            self.wordExplorer = WordExplorer(DBPATH)
            while RootWordSubmissionService.TreeComputer.keepRunning:
                RootWordSubmissionService.TreeComputer.newWordEvent.wait()
                newJSONEchoTreeStr = self.wordExplorer.makeJSONTree(
                    self.wordExplorer.makeWordTree(
                        RootWordSubmissionService.TreeComputer.rootWord))

                # Store the new tree in the appropriate EchoTreeService class variable:
                with EchoTreeService.currentEchoTreeLock:
                    EchoTreeService.currentEchoTree = newJSONEchoTreeStr

                # Signal to the new-tree-arrived event pushers that a new
                # jsonTree has arrived, and they should push it to their clients:
                EchoTreeService.notifyInterestedParties()
                RootWordSubmissionService.TreeComputer.newWordEvent.clear()
                EchoTreeService.log(
                    RootWordSubmissionService.TreeComputer.rootWord)
                EchoTreeService.log(newJSONEchoTreeStr)
Esempio n. 4
0
 def run(self):
     self.wordExplorer = WordExplorer(DBPATH);
     while RootWordSubmissionService.TreeComputer.keepRunning:
         RootWordSubmissionService.TreeComputer.newWordEvent.wait();
         newJSONEchoTreeStr = self.wordExplorer.makeJSONTree(self.wordExplorer.makeWordTree(RootWordSubmissionService.TreeComputer.rootWord));
         
         # Store the new tree in the appropriate EchoTreeService class variable:
         with EchoTreeService.currentEchoTreeLock:
             EchoTreeService.currentEchoTree = newJSONEchoTreeStr;
             
         # Signal to the new-tree-arrived event pushers that a new
         # jsonTree has arrived, and they should push it to their clients:
         EchoTreeService.notifyInterestedParties();
         RootWordSubmissionService.TreeComputer.newWordEvent.clear();
         EchoTreeService.log(RootWordSubmissionService.TreeComputer.rootWord);
         EchoTreeService.log(newJSONEchoTreeStr);