subprocess "handle is invalid" error

Grant Edwards grante at visi.com
Wed Apr 18 15:26:55 EDT 2007


On 2007-04-18, Thomas Heller <theller at ctypes.org> wrote:

> I think this is a subprocess bug.  It is often attributed to
> py2exe because usually developers do never run the script in
> pythonW.exe instead of python.exe, and later build a *windows*
> program with py2exe (the *windows* program has no console, and
> that triggers the bug).

[...]

Ah, excellent analysis.  It does indeed to appear to be a
subprocess bug.  Switching back to os.popen() makes things
"work" again. There's a different problem when the program is
started by double-clicking an associated file in a networked
directory (works fine in a local directory).  That was the
initial problem I was trying to troubleshoot by switching
trying subprocess.Popen().

> The script can be made to work correctly even with pythonW.exe
> (and also as py2exe'd windows program, I just checked it out)
> when the 4 commented out lines are uncommented.  subprocess
> cannot inherit the standard handles when the process has no
> console, you have to create pipes for all 3 channels, and
> close those that are not needed.

Perhaps I'll try switching back to subprocess.Popen() and
creating all three pipes.

> I thought that this bug was fixed in Python2.5.1 (the release candidate),
> but it seems it wasn't.  The bug is at 
> http://sourceforge.net/tracker/index.php?func=detail&aid=1124861&group_id=5470&atid=105470
>
>> If all this is correct, I hope that someone adds a section to the py2exe wiki;

It had been documented at the py2exe wiki -- though it mentions a
different exception.  I added the bug-tracker link and also
that it throws the "invalid handle" exception.

http://www.py2exe.org/index.cgi/Py2ExeSubprocessInteractions

> and reopens the above bug report.

Since I'm still using 2.4.3, I don't think it would be
appropriate for me to do so.

-- 
Grant Edwards                   grante             Yow! It don't mean a
                                  at               THING if you ain't got
                               visi.com            that SWING!!



More information about the Python-list mailing list