Won't the file descriptor stay open until it's garbage collected?   with() could work here, alternatively a try/except/finally block