473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

subprocess "handle is invalid" error

I'm trying to use the py-gnuplot module on windows, and have
been unable to get it to work reliably under Win2K and WinXP.

By default, it uses popen(gnuplotcmd,'w'), but in some
situations that consistently gets an "invalid operand" IOError
when write() is called on the pipe.

So I switched to subprocess. It works fine when executed
"normally" (e.g. "python progname.py"), but when bundled by
py2exe, it always does this:

Traceback (most recent call last):
File "surfedit.py", line 28, in ?
File "Gnuplot\_Gnuplot.pyc", line 178, in __init__
File "Gnuplot\gp_win32.pyc", line 117, in __init__
File "subprocess.pyc", line 533, in __init__
File "subprocess.pyc", line 607, in _get_handles
File "subprocess.pyc", line 634, in _make_inheritable
WindowsError: [Errno 6] The handle is invalid

How does one troubleshoot errors that happen three layers deep
in the subprocess module?

--
Grant Edwards grante Yow! I'm a fuschia bowling
at ball somewhere in Brittany
visi.com
Apr 18 '07 #1
5 14285

"Grant Edwards" <gr****@visi.comwrote in message
news:13*************@corp.supernews.com...

<snip stuff about gnu-plot and py2exe problems>
How does one troubleshoot errors that happen three layers deep
in the subprocess module?
I think the problem is more likely in how your py2exe is getting
bundled, rather than any real problem with the subprocess module. I have
been on the py2exe email list but not really paying much attention... If I
recall correctly, there are some special considerations when using gnuplot
with py2exe? I would suggest digging through the py2exe email archives to
see if you can locate emails on that subject (one copy of which I believe
can be found at:
http://sourceforge.net/mailarchive/f...=py2exe-users), and
if that doesn't work, to direct your question to the py2exe users list at:
py**********@lists.sourceforge.net

(I believe the current home page of the py2exe project is at:
http://sourceforge.net/projects/py2exe/)

Hope that helps,
-ej
Apr 18 '07 #2
On 2007-04-18, Erik Johnson <no****@invalid.comwrote:
>
"Grant Edwards" <gr****@visi.comwrote in message
news:13*************@corp.supernews.com...

<snip stuff about gnu-plot and py2exe problems>
>How does one troubleshoot errors that happen three layers deep
in the subprocess module?

I think the problem is more likely in how your py2exe is
getting bundled, rather than any real problem with the
subprocess module.
I've switched back to os.popen() since I seem to get the same
problems with either. The odd thing is that it only seems to
fail when the current directory is mounted via the network
_and_ when it's being started by clicking on a file whose
filetype is associated with the application.

Running the program from the command line (cmd.exe or bash)
always works for any current directory. Running the program by
cliking on a shortcut icon on the desktop always works for any
'start in' directory.

The one case that doesn't work is when its run by clicking on
an associated file on a network drive.

--
Grant Edwards grante Yow! Now I'm concentrating
at on a specific tank battle
visi.com toward the end of World
War II!
Apr 18 '07 #3
Grant Edwards schrieb:
I'm trying to use the py-gnuplot module on windows, and have
been unable to get it to work reliably under Win2K and WinXP.

By default, it uses popen(gnuplotcmd,'w'), but in some
situations that consistently gets an "invalid operand" IOError
when write() is called on the pipe.

So I switched to subprocess. It works fine when executed
"normally" (e.g. "python progname.py"), but when bundled by
py2exe, it always does this:

Traceback (most recent call last):
File "surfedit.py", line 28, in ?
File "Gnuplot\_Gnuplot.pyc", line 178, in __init__
File "Gnuplot\gp_win32.pyc", line 117, in __init__
File "subprocess.pyc", line 533, in __init__
File "subprocess.pyc", line 607, in _get_handles
File "subprocess.pyc", line 634, in _make_inheritable
WindowsError: [Errno 6] The handle is invalid

How does one troubleshoot errors that happen three layers deep
in the subprocess module?
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).

Consider ths little script:

"""
import os, sys, subprocess

sys.stderr = open("errors.txt", "w")

if os.path.exists("output.txt"):
os.remove("output.txt")

proc = subprocess.Popen("dir", shell=True,
stdout=subprocess.PIPE,
## stderr=subprocess.PIPE,
## stdin=subprocess.PIPE,
)
##proc.stderr.close()
##proc.stdin.close()
data = proc.stdout.read()

open("output.txt", "w").write(data)
"""

It calls 'dir' in the current directory, and writes the output
to the file 'output.txt'. Any errors are written to 'errors.txt'.

When you run this script with python.exe, everything works.
If the script is run with pythonW.exe, nothing works and 'errors.txt'
contains this:

c:\svn\theller>type errors.txt
Traceback (most recent call last):
File "test_subproc.py", line 9, in <module>
stdout=subprocess.PIPE,
File "c:\python25\lib\subprocess.py", line 586, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "c:\python25\lib\subprocess.py", line 699, in _get_handles
p2cread = self._make_inheritable(p2cread)
File "c:\python25\lib\subprocess.py", line 744, in _make_inheritable
DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] Das Handle ist ungültig
c:\svn\theller>

The error message, translated to english, is 'the handle is invalid'.

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.

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...70&atid=105470

If all this is correct, I hope that someone adds a section to the py2exe wiki;
and reopens the above bug report.

Thomas

Apr 18 '07 #4
On 2007-04-18, Thomas Heller <th*****@ctypes.orgwrote:
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...70&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/Py2E...ssInteractions
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!!
Apr 18 '07 #5


Thomas Heller-2 wrote:
>
Grant Edwards schrieb:

[snip]
>>
Traceback (most recent call last):
File "surfedit.py", line 28, in ?
File "Gnuplot\_Gnuplot.pyc", line 178, in __init__
File "Gnuplot\gp_win32.pyc", line 117, in __init__
File "subprocess.pyc", line 533, in __init__
File "subprocess.pyc", line 607, in _get_handles
File "subprocess.pyc", line 634, in _make_inheritable
WindowsError: [Errno 6] The handle is invalid

How does one troubleshoot errors that happen three layers deep
in the subprocess module?

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).

[snip]

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...70&atid=105470

If all this is correct, I hope that someone adds a section to the py2exe
wiki;
and reopens the above bug report.

Thomas
I've been bitten by this same bug in 2.5.1, and the bug you linked to (which
is now @ http://bugs.python.org/issue1124861) is still marked as fixed.

I've tried to reopen it but it seems only the reporter (or some "admin"
user) is able to do it.

--
View this message in context: http://www.nabble.com/subprocess-%22...p14740517.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jan 10 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Morris | last post by:
I'm new to .NET and just trying a few things out, like emailing. I created a form in Visual Studio .Net to input some information for generating an email and I'm getting the following error when it...
1
by: Ron | last post by:
I am trying to run asp.net pages. The server is accessed via http://sitename/username I have verified it is using port 80 and aspx extensions are configured. But when I run and asp.net page I...
9
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
2
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F:...
1
by: John Hunter | last post by:
I've recently had a nasty problem with the "Invalid reference to the property Form" error in subforms - nasty because it doesn't seem to consistently happen to all forms which contain the same...
3
by: Jimski | last post by:
Hello all, I am having a problem where I get an error message when I call FlushFinalBlock when decrypting my encrypted text. I am using the Rijndael algorithm. The error message is "Length...
2
by: Vinod I | last post by:
Hi Team, When I tryed following code, I am getting the Runtime Error as "The View State is invalid for this page and might be corrupted." Exception Details: System.Web.HttpException: The View...
1
by: Abhijeet Nevaskar via .NET 247 | last post by:
Hi , I have very serious problem about printing and i have almost searched the printing section for simillar kind of problem.PrintPreview dialog shows preview of few pages quite well and after...
1
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.