Use python logging framework instead of just writing to file. It will now rotate to 3 times 1 MiB.