cache-like structure

konstantin konstantin.selivanov at gmail.com
Thu Aug 7 15:36:18 EDT 2008


> And if you change the deque for a Queue.Queue, you don't even need a
> Lock...
>
> Cheers,
>
> Maxime

Maxime,

thanks, sched module could be a nice solution. I've never used it
before
but it seems to be the right way.
You guessed right. I want to used it in Queue. But this implementation
does
not guarantee that __cleanup__ won't be invoked while __contains__
processing.

> def _remove(self, rec): #try not to use __form, almost always an error
>    self.records.remove(rec)
>
> the Timer would become
> Timer(ttl, self._remove, [(t, item)]) # t is the time that you got
> before

This solution has one shortcoming. When record() called many times
during
short period (almost simultaneously) the _remove(item) calls do not
manage to
remove records on time. So I choosed batch cleanup.

But thanks for suggestion! I'll try sched.



More information about the Python-list mailing list