Fredrik Holmström on Oct 20th, 2008I’m stunned: wierd problem with python and sockets + threads
Short Explenation:
I have a python script that is a http-server: http://paste2.org/p/89701, when benchmarking it against ApacheBench (ab) with a concurrency level (-c switch) that is lower then or equal to the value i specified in the socket.listen()-call in the sourcecode everything works fine, but as soon as put the concurrency level in apache bench above […]
Fredrik Holmström on Oct 18th, 2008Practical usage of python decorators
This might be a somewhat unorthodox usage of python decorators, but a very practical and nice one - I got a question on IRC from a friend that wanted to store python functions in a dictionary and was complaining that there is no way to use lambdas in python as anonymous closures because of their […]
Fredrik Holmström on Sep 22nd, 2008Python decorators explained
Python decorators is just syntactic sugar to something that has been possible to do in python since version 1.0, for more background/technical information on decorators check out this pep.
The first and most important thing to remember about decorators is this: Whatever that is returned from the decorator function will replace the original function you’re decorating. […]
Fredrik Holmström on Sep 20th, 2008Setting up mod_wsgi for apache on Windows
I just installed mod_wsgi on my windows (yeah yeah, I know…) laptop, it turned out to be amazingly easy but I figured I’d put up notes on how to do it here anyways.
Head over to http://adal.chiriliuc.com/mod_wsgi/ and fetch the latest (at the time of this writing it was revision_1018_2.3) apache module for your combination of […]
Fredrik Holmström on Sep 20th, 2008Javascript-OO & Python-DuckTyping in PHP5.3
With the introduction of closures in PHP5.3 my mind has been working a lot trying to find new (ab-)uses for them, first out is a combination of javascript and python oo - honestly this object model is nicer then the standard PHP one.
This allows for changing objects methods during runtime, proper duck-typing, monkey-patching and a […]
Fredrik Holmström on Sep 12th, 2008Generic dispatching in python
Edit: I figured this had to have been done by someone at some point in the python community, i was right: http://pypi.python.org/pypi/simplegeneric. Very nice implementation indeed, go check it out if you like what you see here.
So, a bit more black-magic in python - this time implementing generic dispatching / functions, or at least - […]
Fredrik Holmström on Sep 11th, 2008Prototype based programming in python
Revision #2:
I updated my code with some more bells and whistles, also removing the double-underscore-method/attributes and operator overloading as some people commented so “nicely” on.
prototype.py
class Object(object):
def __init__(self):
self._parent = None
self._methods = {}
def […]
Fredrik Holmström on Sep 6th, 2008Outputting html from python programmatically
After being stuck with the drudgery of string interpolation when outputting HTML from python I figured there had to be some better way to do it, yes? The combination of a single decorator and a couple of functions proved to be the solution, here’s the code:
Wordpress decided to f*ck up my syntax highlighting in this […]
Fredrik Holmström on Sep 3rd, 2008How super() should be used when calling a parent’s method
Edit: You learn something new every day, it turns I was the disillusioned one, the correct way to call super is actually this:
class Demo(object):
def __init__(self):
print “From Demo”
class Test(Demo):
[…]
Fredrik Holmström on Sep 1st, 2008Managing asynchronous operations with python generators (part3)
Part 1: Introduction to generators in Python
Part 2: Indepth generator usage in Python (part2)
Part 3: Managing asynchronous operations with python generators (part3)
You can download all the code for this part here: http://totmacher.eu/upload/generators.tar.gz
I’m sorry, I lied to you guys - this part will not contain a real world example because I felt there were to many […]