[Zope3-Users] Re: Starting thread in object deserialize

Alek Kowalczyk thealx at poczta.onet.pl
Sun Apr 16 13:39:09 EDT 2006


I'll try to explain that a wee bit more, here is the Use Case:

I have an IMonitorsContainer containing IMonitor(s).
When a user creates new Monitor instance (using "Add Monitor" on the 
web), the created Monitor should start thread and periodically perform 
measurements (configured by the user by setting some Monitor's fields) 
in that thread - until the Monitor is deleted (by the user on the web 
interface).
Or until Zope is eventually stopped/killed. When Zope is later started 
again, the persisted Monitors (i.e configuration of measurement threads) 
should be restored from ZODB, create and start the threads again after 
restored, and continue performing measurements.

Florent Guillaume wrote:
>
>
> That can't work. The same persistent object may exist in several 
> threads at the same time, with a different identity. But it's still 
> the same object w.r.t. the persistence machinery. (This is due to 
> multiple ZODB connections and caching.)
>
> Please detail a bit more what are your needs and use cases.
>
> Florent
>
> Alek Kowalczyk wrote:
>> Hello,
>>
>> I have an object which needs to be associated with a thread. The thread
>> should be started on object creation and stopped when object is removed
>> or zope is stopped. The object is persistent - there is a possibility
>> that it will be created by both web interface and when starting zope
>> (deserializing objects).
>>
>> How to assure that the thread will be properly started on
>> deserialization, and properly stopped on object removal?
>> I read through documentation of Events and I suspect I might subscribe
>> to IObjectCreatedEvent and IObjectRemovedEvent for that.
>> Or will it be enough just to start thread in __init__ and remove it in
>> __del__ of the object?
>>
>> Regards,
>> Alek
>
>



More information about the Zope3-users mailing list