#!/usr/bin/env python import time import zipfile import os try: # Create a zero byte zip file for this test: fp= open("zero.zip","wb") fp.close() fp= 0 z= zipfile.ZipFile("zero.zip","r") # A handle is now open to 10151540.zip except: try: print("The opening of the ZipFile context failed. However you can " "now see an open handle to the file if you look with process " "explorer (www.sysinternals.com)") time.sleep(60) #The handle exists here. Use processExplorer to see it os.remove("zero.zip") except: print "Remove failed!" time.sleep(60) try: # This remove works, since the handle went away after that last # exception for reasons I don't understand os.remove("zero.zip") except: print "Second Remove failed!"