[issue3210] subprocess.Popen does not release process handles if process cannot be started

Geoffrey Bache report at bugs.python.org
Thu Jun 26 17:22:42 CEST 2008


New submission from Geoffrey Bache <gjb1002 at users.sourceforge.net>:

Run the following code on Windows:

import subprocess, os

file = open("filename", "w")
try:
    proc = subprocess.Popen("nosuchprogram", stdout=file)
except OSError:
    file.close()
    os.remove("filename")

This produces the following exception:

Traceback (most recent call last):
  File "C:\processown.py", line 10, in <module>
    os.remove("filename")
WindowsError: [Error 32] The process cannot access the file because it
is being used by another process: 'filename'

When the CreateProcess call fails the subprocess module should release
the handles it provides. Unfortunately it seems to raise WindowsError
before doing this.

See also
http://groups.google.com/group/comp.lang.python/browse_thread/thread/6157691ea3324779/6274e9f8bc8a71ee?hl=en#6274e9f8bc8a71ee

As Tim Golden points out, this can be worked around by doing
os.close(file.fileno()) at the end instead of file.close()

----------
components: Extension Modules
messages: 68787
nosy: gjb1002
severity: normal
status: open
title: subprocess.Popen does not release process handles if process cannot be started
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3210>
_______________________________________


More information about the Python-bugs-list mailing list