Posts

Showing posts from December, 2008

Being naïve about Python object identities, references and sizes.

I'm ashamed of how naïve and ignorant I stand regarding Python stuff. At least this time, I've learned a great lesson about object identities, references and sizes. Hopefully you won't make the same mistake as I did.

Here's what I wanted to do: write an in-memory simplistic log keeper for my application, that would be used as a poor man's brute force protection. The details don't matter much. All this meant is I'd have to keep, say, all the last 10 authentication attempts for all users, for as long as needed, in memory.

I was then a bit worried about memory usage, so I got creative. I'm probably the electrician sysadmin that Tom referred. Sometimes the wires burst in flames when I get creative.

A normal (and sane) person would write something like this:


UserLog(object):
def __init__(self, auth_result, auth_timestamp, client_ip):
self.auth_result = auth_result
self.auth_timestamp = auth_timestamp
self.client_ip = client_ip

It's a simple class …