Re: Keeping track of online users
On Nov 3, 12:07 am, JoeJ <[EMAIL PROTECTED]> wrote: > Are you looking for something like 'django-tracking' ?? > http://code.google.com/p/django-tracking/ > > I was just perusing this last night, for use on a site of mine. > > -- joe excuse me for late... thank you very much :) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Keeping track of online users
so,how can i use it in GAE? 2008/11/3 JoeJ <[EMAIL PROTECTED]> > > > Are you looking for something like 'django-tracking' ?? > http://code.google.com/p/django-tracking/ > > I was just perusing this last night, for use on a site of mine. > > -- joe > > > On Nov 1, 3:52 pm, "[EMAIL PROTECTED]" > <[EMAIL PROTECTED]> wrote: > > I have found some post of 2007 on this argument but maybe with django > > 1.0 something is changed. > > > > how do you do that ? > > > > thanks everyone :) > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Keeping track of online users
Are you looking for something like 'django-tracking' ?? http://code.google.com/p/django-tracking/ I was just perusing this last night, for use on a site of mine. -- joe On Nov 1, 3:52 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have found some post of 2007 on this argument but maybe with django > 1.0 something is changed. > > how do you do that ? > > thanks everyone :) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Keeping track of online users
Can you be more specific? What are you trying to do? -Jeff On Nov 1, 3:52 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have found some post of 2007 on this argument but maybe with django > 1.0 something is changed. > > how do you do that ? > > thanks everyone :) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Keeping track of online users
I have found some post of 2007 on this argument but maybe with django 1.0 something is changed. how do you do that ? thanks everyone :) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: keeping track of online users
So, here is my version, using the cache backend: from datetime import timedelta, datetime from django.core.cache import cache from django.contrib.sites.models import Site ONLINE_MINUTES = 10 CACHE_KEY = '%s_online_user_ids' % Site.objects.get_current().domain _last_purged = datetime.now() def get_online_user_ids(): user_dict = cache.get(CACHE_KEY) return hasattr(user_dict, 'keys') and user_dict.keys() or [] class OnlineUsers(object): def process_request(self, request): if request.user.is_anonymous(): return user_dict = cache.get(CACHE_KEY) if not user_dict: # initialization user_dict = {} now = datetime.now() user_dict[request.user.id] = now # purge global _last_purged if _last_purged + timedelta(minutes=ONLINE_MINUTES) < now: purge_older_than = now - timedelta(minutes=ONLINE_MINUTES) for user_id, last_seen in user_dict.items(): if last_seen < purge_older_than: del(user_dict[user_id]) _last_purged = now cache.set(CACHE_KEY, user_dict, 60*60*24) This stores a dictionary in the form: {user_id: last_seen_time, ...} in the cache and updates the cache once for every request by an authenticated user. An alternative would be to store a structure like Jeremy's, {minute_seen: set(user_id, ...), ...} which I think will result in nearly the same amount of cache hits on average. I would like to hear your comments. On 3 Ekim, 16:09, "Marty Alchin" <[EMAIL PROTECTED]> wrote: > On 10/3/07, omat <[EMAIL PROTECTED]> wrote: > > > I used it for some time and observed some inconsistencies. I think > > this is because the code is not thread-safe. > > > Do you know a thread safe way of applying this approach? > > Well, "thread-safe" is a confusing term for something like this, but > you're right that it has to do with the operating environment. I had > similar problems with an application of mine, when I used a > module-level dictionary to store a cache that would be updated. What I > ended up having to do is using Django's cache framework, which will > work fine in multi-process setups, as long as you don't use the > "simple" or "local" cache backends. > > Don't let the local backend's claim of being multi-process thread-safe > fool you. What that means is that multiple threads and processes won't > interact with each other, which is the usual definition of the term. > But since you actually do want multiple threads and processes to share > that information, its multi-process/thread-safety is actually a > problem. That's why I said it's a confusing term for this situation. > If you use the file, db or memcached backends, you should be fine. > > -Gul --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: keeping track of online users
On 10/3/07, omat <[EMAIL PROTECTED]> wrote: > I used it for some time and observed some inconsistencies. I think > this is because the code is not thread-safe. > > Do you know a thread safe way of applying this approach? Well, "thread-safe" is a confusing term for something like this, but you're right that it has to do with the operating environment. I had similar problems with an application of mine, when I used a module-level dictionary to store a cache that would be updated. What I ended up having to do is using Django's cache framework, which will work fine in multi-process setups, as long as you don't use the "simple" or "local" cache backends. Don't let the local backend's claim of being multi-process thread-safe fool you. What that means is that multiple threads and processes won't interact with each other, which is the usual definition of the term. But since you actually do want multiple threads and processes to share that information, its multi-process/thread-safety is actually a problem. That's why I said it's a confusing term for this situation. If you use the file, db or memcached backends, you should be fine. -Gul --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
keeping track of online users
Hi, In this thread, closed due to inactivity: http://groups.google.com/group/django-users/browse_thread/thread/6f5f759d3fd4318a/ Jeremy Dunck offers a resource friendly way to keep track of online users (http://groups.google.com/group/django-users/attach/ c2f60227b0f2d040/OnlineUsers.py?part=2) I used it for some time and observed some inconsistencies. I think this is because the code is not thread-safe. Do you know a thread safe way of applying this approach? Regards, oMat --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---