Removed with statement for compatibility with python < 2.6. Using try finally instead.