[Server-devel] [PATCH] Introducing: server side traffic control

Jim Tittsler jim at OnNZ.net
Wed Jun 25 04:33:02 EDT 2008


On Jun 25, 2008, at 12:18, martin.langhoff at gmail.com wrote:

I write a lot of my "shell scripts" in Python, so I recognize the  
style... but I can't help a couple of comments.

> +    os.system('touch ' + recentclientsdir + '/' + clientid)

I would write that:
     open(os.path.join(recentclientsdir, clientid), 'wb').write('')
although if you really want it to be able to fail silently, it would  
need to be wrapped in a try: except IOError: pass.

> +    clientcount = os.system('find ' + recentclientsdir +
> +                            ' -mmin -5 -type f | wc -l');

And your use of 'find' here and a bit further on is really succinct,  
but I would use subprocess instead of system so I didn't have to  
spend time worrying about what recentclientsdir was set to.  Or do it  
in Python which won't be nearly as concise (barring a hard to read  
list comprehension).

clientcount = 0
root, dirs, files = os.walk(recentclientsdir).next()
for file in files:
	if time.time() - os.stat(os.path.join(root, file)).st_mtime < 5*60:
		clientcount += 1

> +    if (clientcount > 10 ):
> +        return apache.HTTP_SERVICE_UNAVAILABLE

Jim
peanut gallery


-- 
Jim Tittsler, Gisborne     http://www.OnNZ.net/      GPG: 0x01159DB6
Python Starship  http://Starship.Python.net/crew/jwt/
Mailman IRC      irc://irc.freenode.net/#mailman





More information about the Server-devel mailing list