Coder speaks louder. HTH.

#Pseudo code. Not tested nor proven.
class TimeoutTimerPool(object):
  """A pool that tracks a set of users and their active session.
Tipically used as a singleton."""
  from threading import Timer
  def __init__(self):
    self.pool = {}
  def expiration_handler(self, session_id, user_id):
    #Take action with session_id and/or user_id here
    pass
  def register_user_presence(self, session_id, user_id):
    """Tracks user activity/presence. No magic mojo here, must be
called manually (or integrated in some middleware)."""
    # Timers can be reset. So, we just dispose the current and create another.
    self.unregister_session(session_id)
    self.pool[session_id] = Timer(SESSION_TIMEOUT_OR_SOMETHING,
self.expiration_handler, session_id, user_id)
    self.pool[session_id].start()
  def untrack_session(self, session_id):
    """Forfeits user tracking. For logouts and such."""
    if self.pool.haskey(session_id):
      current_timer = self.pool[session_id]
      if current_timer.isAlive():
        current_time.cancel()
      # Don't kow if this is the right way to dispose a Timer
      del self.pool[session_id]

Cheers,
Paulo Köch

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to