Sunday, 16 August 2009

Old-style class lookup

By the wide adoption of Python 3 and the discontinuation of maintenance for 2.x, old-style classes will be gone. This also means that there's no way to easily change the magic-methods of your objects (there is of course a way by manually writing the wrappers and replacing the methods they are wrapping, but I don't count that as being easy any more). So today I have written a metaclass that makes your class mimic the behaviour of old-style classes in 2.x. It does that by automatically generating said wrappers and storing the real methods in a closure.

Here you got the code that allows this and also contains an example that verifies that it works. As said in the doc-string, I wouldn't recommend using this for any purpose other than experimenting.

Thursday, 6 August 2009

epoll is awesome

It really is. Tonight I had the idea of trying out something crazy with epoll. I tried out what happens if you modify the flags of a fd in a thread while the epoll.poll call is blocking the main one. I didn't really expect it to mind the changes done by the thread but - unlike poll - epoll does. This is really nifty and I am sure can be put to good use (though I have to admit I cannot think about one just yet). What perplexes me is that this is not documented - neither in the (rather sparse) Python documentation of select.epoll, nor in the Linux manpage for epoll. All I could find was a "They are thread safe", but that's in an a bit different context.

I'm thinking about creating an API for asynchia that abstracts changes the the socket-map from other threads (you are not expected to understand this if you are not familiar with asynchia).

I have also written code that illustrates how this works with epoll, and how it does not with poll.