473,714 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(gnuplotcm d,'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.p y", line 28, in ?
File "Gnuplot\_Gnupl ot.pyc", line 178, in __init__
File "Gnuplot\gp_win 32.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_inheritab le
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 14324

"Grant Edwards" <gr****@visi.co mwrote in message
news:13******** *****@corp.supe rnews.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**********@li sts.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.co mwrote in message
news:13******** *****@corp.supe rnews.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(gnuplotcm d,'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.p y", line 28, in ?
File "Gnuplot\_Gnupl ot.pyc", line 178, in __init__
File "Gnuplot\gp_win 32.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_inheritab le
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.tx t", "w")

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

proc = subprocess.Pope n("dir", shell=True,
stdout=subproce ss.PIPE,
## stderr=subproce ss.PIPE,
## stdin=subproces s.PIPE,
)
##proc.stderr.c lose()
##proc.stdin.cl ose()
data = proc.stdout.rea d()

open("output.tx t", "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.p y", line 9, in <module>
stdout=subproce ss.PIPE,
File "c:\python25\li b\subprocess.py ", line 586, in __init__
errread, errwrite) = self._get_handl es(stdin, stdout, stderr)
File "c:\python25\li b\subprocess.py ", line 699, in _get_handles
p2cread = self._make_inhe ritable(p2cread )
File "c:\python25\li b\subprocess.py ", line 744, in _make_inheritab le
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.Pope n().
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.Pope n() 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.p y", line 28, in ?
File "Gnuplot\_Gnupl ot.pyc", line 178, in __init__
File "Gnuplot\gp_win 32.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_inheritab le
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
4611
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 executes both on my server or on the server of the .NET service provider. I'm obviously missing something very basic and I'm hoping one of you can point out my error. Thank you for your assistance. Brian
1
3890
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 get the following error: Invalid file name for monitoring: 'E:\'. File names for monitoring must have absolute paths, and no wildcards. Description: An unhandled exception occurred during the
9
1966
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 Basic .Net application. I have researched MSDN for help and found the example article 321900 (see below) and set up a test and everything works fine when I use SQL Server 2000 but when I modify the code and use data from Access 2000 using an...
2
22812
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: operator delete(void*) (vg_replace_malloc.c:156) ==11604== by 0x804A1BA: __gnu_cxx::new_allocator<Foo>::deallocate(Foo*, unsigned) (new_allocator.h:86) ==11604== by 0x8049C08: std::_Vector_base<Foo, std::allocator<Foo> >::_M_deallocate(Foo*,...
1
5410
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 structure and code. Judging by the forums I've researched, it's not an uncommon error. I'm happy to say I've found a simple solution. OVERVIEW: I have a main form (no record source) which contains two subforms. The subforms are not linked, but...
3
29268
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 of the data to decrypt is invalid" and occurs on the csDecrypt.FlushFinalBlock.
2
3214
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 State is invalid for this page and might be corrupted. Stack Trace: System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +150 System.Web.UI.Page.LoadPageViewState() +16
1
3073
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 that code raises the exception "NO PRINTERS INSTALLED" OR " HANDLE IS INVALID". can u hepl me ?? Thanks in advance. Regards, Abhijeet.
1
8030
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: http://(address.of.my.webcam):port/LiveView.html and
0
8803
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8711
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7953
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5948
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4726
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.