I don't find this to be any better: https://gist.github.com/mpetazzoni/d7e4df97d9be006d21a0 since you need to manage file closing.