Knowledge Collector

Alain Hernandez Lopez ahernandezlop at estudiantes.uci.cu
Tue May 29 05:53:09 UTC 2007


Hi Maurits

> In your case, InformationSources are stored in a KnowledgeCollector,
> right?
 
Yes, InformationSources are stored in a KnowledgeCollector

>And are DownloadedDocuments stored in the KnowledgeCollector too, or
>in their own InformationSource?
 
DownloadedDocuments are stored in the KnowledgeCollector

> Let me rephrase that in light of the rest of the sentence:  before
> zope is restarted, KnowledgeCollectors *can* be created.  Correct?

Yes, sorry, I'm cuban. 


> PersistentList Should Work (tm).  Can you show us some code?
 
Next I show you the code of the main thread class that has the __jobList, this is the list that I would like to make persistent.
 
##code-section module-header #fill in your manual code here
##/code-section module-header
import threading 
import datetime
import time
import string
from childThread import childThread
from ZODB.PersistentList import PersistentList
from persistent import Persistent
START_TIME1 = '2007-05-12 23:59:59.9999999'
START_TIME2 = '2007-05-12 01:00:00.000000'
class schedulerThread(threading.Thread,Persistent):
    ''' '''
    def __init__(self):
        """
        Class Constructor..
        """
        threading.Thread.__init__(self)
        self.__jobList = PersistentList()
        
    def setJob(self, job):
        """
        Add job to the Scheduler.
        """
        self.__jobList.append(job)
    def _executeJob(self, job):
        """
        Execute Scheduler jobs.
        """
        class Child(threading.Thread):
            def __init__(self):
                threading.Thread.__init__(self)
                """
                Class Constructor.
                """
                pass
           
            def run(self):
                """
                Exe
                """
                job()
        c = Child()
        c.start()
        #c = childThread(job)
        #c.start()
    def run(self):
        """
        Run Scheduler jobs
        """
 print "Se ha creado el hilo del portal scheduler tool"
        cont = 0
        while True:
            localTime = datetime.datetime.now()
            if self._date_timeUnpack(str(localTime)) > self._date_timeUnpack(START_TIME1) and \
               self._date_timeUnpack(str(localTime)) < self._date_timeUnpack(START_TIME2):
                for job in self.__jobList:
                    self._executeJob(job)
                    print 'Ejecutando hilo%d' %(cont) 
                    cont += 1 
            sleepTime = self._compute_sleepTime(self._datetimeSubtraction(START_TIME1,str(localTime)))
            
            print "Durmiendo %d segundos, la hora es %s" % (sleepTime,str(datetime.datetime.now()))
            
            time.sleep(sleepTime)
                 
            
    def _date_timeUnpack(self,datetime):
        """
        Unpack
        """
        s = datetime
        year, month, day, hour, min, sec, mic= s[0:4], s[5:7], s[8:10], s[11:13], s[14:16], s[17:19], s[20:]
        return [hour, min, sec, mic]
    def _datetimeSubtraction (self, datetime1, datetime2):
        """
        
        """
        list = []
        datetime1unpack = self._date_timeUnpack(datetime1)
        datetiem2unpack = self._date_timeUnpack(datetime2)
      
        if datetime1unpack > datetiem2unpack:
            for x,y in zip(datetime1unpack, datetiem2unpack):
                list.append(int(x)-int(y))
        else:
             list=[0,2,0]
        return list
    def _compute_sleepTime(self,list): 
        return list[2]+list[1]*60+list[0]*3600
    
    def set__jobList(self,value):
        self.__jobList=value
    def get__jobList(self):
        return self.__jobList
    
    def del_job(self,job):
        """
          Elimina la tarea cuando se elimina un KC.
        """
        if job in self.__jobList:
        self.__jobList.remove(job)
   
##code-section module-footer #fill in your manual code here
##/code-section module-footer

Thanks for your help Maurits






More information about the Product-Developers mailing list