[albatross-users] SessionFileAppMixin has no session_age
Andrew McNamara
andrewm at object-craft.com.au
Tue Jan 28 11:53:11 EST 2003
> Is there a technical reason why SessionFileAppMixin has no 'session_age'
> argument? I see it in SessionServerApp, and I'd like to use it in the
> File version. Just wondering if this has already been attempted and
> wasn't able to be easily done, or if it's just not being dealt with.
With the SessionServer sessions, you have a single session daemon, which
can track sessions and clean out old ones, but with the SessionFile
implementation, processes come and go, so I decided it should really be
an external mechanism.
Under Unix, you would probably just have a cron job that cleaned out any
files with a modification date older than some age. Something like this
would remove sessions older than a day:
find /some/session/dir -mtime +1 | xargs rm
What's probably needed is a python equivilent, something like (WARNING -
UNTESTED):
import os, time
def session_clean(dir, age):
"""
Scan "dir" for files older than "age" seconds, and remove them
"""
expire_time = time.time() - age
for filename in os.listdir(dir):
filepath = os.path.join(dir, filename)
if os.path.getmtime(filepath) < expire_time:
os.unlink(filepath)
--
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/
More information about the Albatross-users
mailing list