[ZODB-Dev] Deferred notifing from one thread to another.
Victor Safronovich
vsafronovich at naumen.ru
Fri Dec 9 11:33:40 EST 2005
Hello Tim Peters,
Friday, December 9, 2005, 9:18:26 PM, you wrote:
TP> [Victor Safronovich]
>> ...
>> Of course i may write time.sleep( SLEEP_CONSTANT ) before
>> app._p_jar.sync(), but is this a good solution?
TP> I can't make time to understand your problem (sorry!)
Tim, thank you for your answer.
TP> , but I can make time
TP> to tell you that a bare time.sleep() is almost never a good solution to
TP> thread problems. time.sleep() in a _loop_ can be reliable, provided you can
TP> write code to recognize when what you're waiting for has happened; this
TP> approach is called "polling".
TP> while what I'm waiting for hasn't happened:
TP> time.sleep(WHATEVER)
TP> For example, when you change a persistent object, its ._p_changed attribute
TP> gets set to a true value. When the change gets committed, ._p_changed is
TP> reset to a false value. So _perhaps_ (I'm not sure -- being sure would
TP> require understanding all of your problem) you could poll waiting for some
TP> specific object's _p_changed to become false.
Supper, I do the next
def reset_hook( scheduler ):
while scheduler._p_changed:
time.sleep(0.05) # again time sleep :))
ResetEvent.set()
and
def addSchedulerElement(self, **options):
self._setObject(self.generateId(), ScheduleElement(**options))
Thread(target=reset_hook, args=(self,))
Tommorow, i`ll check how this works :).
--
Best regards,
Victor Safronovich
NauMen.NauDoc.SoftwareDeveloper http://www.naumen.ru
More information about the ZODB-Dev
mailing list