Showing all posts by Dan
Migrating from Python 2 to Python 3

As the world evolves, one may want to take on new opportunities to get better things out of the door, e.g. use the “new” async paradigm or make better use of generators and iterators. This means using Python 3 – and this also usually means migrating large codebases from Python 2. Sometimes this is as easy as flipping the bit, other times it may be better to just refactor the whole code. Let me point out some differences, though.

1. print

This one is easy – most of the time it’s just about translating code from:

print "abcd"

to:

print("abcd")

Continue Reading →

Hero culture is bad

Some years ago, back in the country I grew up in, back to an age when I was still watching TV, there was a certain trend: TV stars would move their shows to different stations and find themselves, months later, in a bad position.

Even if they were initially offered better packages and maybe were able to take some of their initial staff with them on the new venture, they ultimately failed to actually move audiences for more than a limited period of time. Some of them ended being thrown out of TV business for good.

Tabloids would sometime chime in and ask questions in the line of “how was that even possible?”, but they would not post answers (not that they had anything meaningful to say). I’m not sure their readers would have had any chance of understanding what was really going on, though.

I wasn’t at that time in any position to understand what was going on either, even if I did have access to smarter opinions in the line of “the shows were actually better before the move” or “some stations have more money to spend on everything and can afford not to cut corners”. That’s actually the visible layer: I had to move jobs myself a couple of times to realize what the success is about. To summarize:

  • it’s not about you having some special talent;

  • it’s not about you pulling the company uphill by yourself;

  • it is about the whole environment that makes you succeed or fail, starting from how clean is the toilet at your work place.

Continue Reading →

Using Linux network namespaces

You don’t get to explicitly use Linux namespaces very often; one usually gets to make use of them when setting up containers or some sort of smart web hosting platform that allows hard resource limits to be put in place for customers, but even then the actual setup is hidden somewhere in the back. There are scenarios when containers simply require too much work for the particular task; I, at one time, faced the need of ensuring some network communication between 2 instances of the same service.

Communication? Same service? Have them listen on different addresses or on different ports and you’re done, you might say – but it’s not always that simple. If you have no control over the code but just want to replicate a certain behavior, there may simply not be an option to have instances listen on different ports. If the protocol also involves broadcasting, things become really complicated, as you don’t always have 2 IP addresses, on different interfaces, connected to the same network. Such scenario is easy to solve with virtualization or containers, but for this particular problem they’re overkill. The lightweight solution comes from manipulating Linux network namespaces.

Continue Reading →

Next Page