Debugging Python Code

People on my team asked me some time ago how I debug things in our python code base. So I thought I’d share here.

The easiest (and least efficient) way to debug is to use print statements and logging. But since you’re not using a real debugger, you need to update the code and rerun in order to get new results.

Hence the most efficient way to debug things in python is to use a debugger. Don’t be scared, they are easy to master and they’ll serve you nicely for the rest of your life. They all are very similar.

Keep reading

Unpack container image using docker-py

This is just a quick blog post. I’ve seen a bunch of questions on docker-py’s issue tracker about how to extract a container image using docker-py and get_archive (a.k.a. docker export).

Keep reading

Non-blocking stdin with python using epoll

I was playing with epoll and was curious whether I can use it to monitor sys.stdin. The biggest issue was that sys.stdin.read() is blocking and I had no way to figure out whether I read the descriptor fully or not (making the epoll useless pretty much). Until I changed it to non-blocking with fcntl.

Keep reading

Installing python packages from git via pip

It may happen that you need to install a python project with pip from git(hub). That’s pretty easy:

Keep reading