Allan.cu wrote:
>
>
> 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)
>
This looks strange to me. I don't think it makes sense to have a
*persistent* thread.
For an object to be persisted, it needs to be attached to some other object
that is also persisted. Most commonly, you'll create a content type. All
content type objects are persistent (no need to derive from Persistent
yourself, since that's already done further up the hierarchy). If you set an
attribute on a persistent object, it's saved so long as the thing being set
is also persistable (i.e. it's a primitive or an object derived from
Persistent).
I suggest that you make your thread access some content object, and persists
things on that. It's not clear to me where your threads are being
initialized from, though.
Martin
--
View this message in context:
http://www.nabble.com/Knowledge-Collector-tf3828499s20094.html#a10850752
Sent from the Product Developers mailing list archive at Nabble.com.
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers