473,694 Members | 2,689 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 14316

"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
4608
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
3886
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
22805
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
5406
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
29256
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
3208
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
3067
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
8023
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
8616
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
9110
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8818
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7650
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...
1
6481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5825
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
4332
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...
3
1970
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.