import os from _subprocess import * import msvcrt class P: def __init__ (self, handle): handle = msvcrt.get_osfhandle (f.fileno ()) handle2 = DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(), 0, 1, DUPLICATE_SAME_ACCESS) raise RuntimeError f = open ("filename", "w") try: p = P (f) except RuntimeError: f.close () try: os.remove ("filename") except WindowsError: print "SUCCESS: Failed as expected" else: print "FAILURE: Succeeded unexpectedly"