Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7402 > unrolled thread
| Started by | virdo <virdoo@gmail.com> |
|---|---|
| First post | 2011-06-10 13:42 -0700 |
| Last post | 2011-06-10 15:34 -0700 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
Help with a piping error virdo <virdoo@gmail.com> - 2011-06-10 13:42 -0700
Re: Help with a piping error John Gordon <gordon@panix.com> - 2011-06-10 20:48 +0000
Re: Help with a piping error virdo <virdoo@gmail.com> - 2011-06-10 13:56 -0700
Re: Help with a piping error Hans Mulder <hansmu@xs4all.nl> - 2011-06-10 23:56 +0200
Re: Help with a piping error virdo <virdoo@gmail.com> - 2011-06-10 15:34 -0700
| From | virdo <virdoo@gmail.com> |
|---|---|
| Date | 2011-06-10 13:42 -0700 |
| Subject | Help with a piping error |
| Message-ID | <6e035898-8938-4a61-91de-7a0ea7ead8ab@y30g2000yqb.googlegroups.com> |
Hi, I'm getting the following error and I can't Google my way out of it: close failed in file object destructor: sys.excepthook is missing lost sys.stderr My python file is simple print "test". I run it, it works no problem. I pipe the output to a file "run > logfile" and that's the error I get. This is with Windows Server 2008 (64 bit) using ActivePython 2.7.1.4 (64 bit). Cheers,
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2011-06-10 20:48 +0000 |
| Message-ID | <istvuf$bp1$1@reader1.panix.com> |
| In reply to | #7402 |
In <6e035898-8938-4a61-91de-7a0ea7ead8ab@y30g2000yqb.googlegroups.com> virdo <virdoo@gmail.com> writes:
> My python file is simple print "test". I run it, it works no problem.
> I pipe the output to a file "run > logfile" and that's the error I
> get. This is with Windows Server 2008 (64 bit) using ActivePython
> 2.7.1.4 (64 bit).
Are you using an actual pipe symbol in your command? Your post title
suggests you are, but your sample command uses the greater-than symbol.
It's always best to include the actual command and the actual output
rather than typing it by hand, specifically to avoid errors like this.
Please repost a transcript of your real session.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | virdo <virdoo@gmail.com> |
|---|---|
| Date | 2011-06-10 13:56 -0700 |
| Message-ID | <106f3ccb-0a12-490d-bd21-8d6c42dd829c@16g2000yqy.googlegroups.com> |
| In reply to | #7403 |
On Jun 10, 4:48 pm, John Gordon <gor...@panix.com> wrote: > In <6e035898-8938-4a61-91de-7a0ea7ead...@y30g2000yqb.googlegroups.com> virdo <vir...@gmail.com> writes: > > > My python file is simple print "test". I run it, it works no problem. > > I pipe the output to a file "run > logfile" and that's the error I > > get. This is with Windows Server 2008 (64 bit) using ActivePython > > 2.7.1.4 (64 bit). > > Are you using an actual pipe symbol in your command? Your post title > suggests you are, but your sample command uses the greater-than symbol. My apologies, I miswrote. It is the greater than symbol rather than a pipe. Example: c:\PRG>test.py > test.log close failed in file object destructor: sys.excepthook is missing lost sys.stderr
[toc] | [prev] | [next] | [standalone]
| From | Hans Mulder <hansmu@xs4all.nl> |
|---|---|
| Date | 2011-06-10 23:56 +0200 |
| Message-ID | <4df292f8$0$49179$e4fe514c@news.xs4all.nl> |
| In reply to | #7404 |
On 10/06/11 22:56:06, virdo wrote: > On Jun 10, 4:48 pm, John Gordon<gor...@panix.com> wrote: >> In<6e035898-8938-4a61-91de-7a0ea7ead...@y30g2000yqb.googlegroups.com> virdo<vir...@gmail.com> writes: >> >>> My python file is simple print "test". I run it, it works no problem. >>> I pipe the output to a file "run> logfile" and that's the error I >>> get. This is with Windows Server 2008 (64 bit) using ActivePython >>> 2.7.1.4 (64 bit). >> >> Are you using an actual pipe symbol in your command? Your post title >> suggests you are, but your sample command uses the greater-than symbol. > > My apologies, I miswrote. It is the greater than symbol rather than a > pipe. > > Example: > > c:\PRG>test.py> test.log > close failed in file object destructor: > sys.excepthook is missing > lost sys.stderr I think your problem is that some other process still has opened the file test.log and Python cannot write it. Unfortunately, Python only finds out when it is shutting down and cleaning out the "sys" module. An exception is raised, but sys.excepthook has already been disposed. Python's normal fallback stategy is to write the exception and the traceback to sys.stderr. Unfortunately, sys.stderr has been disposed as well. I get a similar message if I try to write to a closed pipe: $ python -c 'print "test"' | false close failed in file object destructor: sys.excepthook is missing lost sys.stderr $ I think this is a bug in Pyhton: the interpreter should flush sys.stdout before tering dwn the 'sys' module, so that it can report an excption if the flush attempt fails. A work-around is to add "import sys" at the top of your script, and "sys.stdout.flush()" at the bottom: import sys print "test" sys.stdout.flush() That should report a proper exception; for example: $ python -c 'import sys; print "test"; sys.stdout.flush();' | false Traceback (most recent call last): File "<string>", line 1, in <module> IOError: [Errno 32] Broken pipe $ Hope this helps, -- HansM
[toc] | [prev] | [next] | [standalone]
| From | virdo <virdoo@gmail.com> |
|---|---|
| Date | 2011-06-10 15:34 -0700 |
| Message-ID | <b4f6957e-7bc0-4bb2-916e-46bce76b1b97@v8g2000yqb.googlegroups.com> |
| In reply to | #7410 |
On Jun 10, 5:56 pm, Hans Mulder <han...@xs4all.nl> wrote:
> On 10/06/11 22:56:06, virdo wrote:
>
>
>
>
>
>
>
>
>
> > On Jun 10, 4:48 pm, John Gordon<gor...@panix.com> wrote:
> >> In<6e035898-8938-4a61-91de-7a0ea7ead...@y30g2000yqb.googlegroups.com> virdo<vir...@gmail.com> writes:
>
> >>> My python file is simple print "test". I run it, it works no problem.
> >>> I pipe the output to a file "run> logfile" and that's the error I
> >>> get. This is with Windows Server 2008 (64 bit) using ActivePython
> >>> 2.7.1.4 (64 bit).
>
> >> Are you using an actual pipe symbol in your command? Your post title
> >> suggests you are, but your sample command uses the greater-than symbol.
>
> > My apologies, I miswrote. It is the greater than symbol rather than a
> > pipe.
>
> > Example:
>
> > c:\PRG>test.py> test.log
> > close failed in file object destructor:
> > sys.excepthook is missing
> > lost sys.stderr
>
> I think your problem is that some other process still has opened the
> file test.log and Python cannot write it. Unfortunately, Python only
> finds out when it is shutting down and cleaning out the "sys" module.
> An exception is raised, but sys.excepthook has already been disposed.
> Python's normal fallback stategy is to write the exception and the
> traceback to sys.stderr. Unfortunately, sys.stderr has been disposed
> as well.
>
> I get a similar message if I try to write to a closed pipe:
>
> $ python -c 'print "test"' | false
> close failed in file object destructor:
> sys.excepthook is missing
> lost sys.stderr
> $
>
> I think this is a bug in Pyhton: the interpreter should flush sys.stdout
> before tering dwn the 'sys' module, so that it can report an excption if
> the flush attempt fails.
>
> A work-around is to add "import sys" at the top of your script, and
> "sys.stdout.flush()" at the bottom:
>
> import sys
> print "test"
> sys.stdout.flush()
>
> That should report a proper exception; for example:
>
> $ python -c 'import sys; print "test"; sys.stdout.flush();' | false
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> IOError: [Errno 32] Broken pipe
> $
>
> Hope this helps,
>
> -- HansM
Thank you Hans! I've got it working, and posting it in case others end
up running into the same problem.
When I first changed the python test.py file to :
import sys
print "yes"
sys.stdout.flush()
I got :
>test2.py > test2.log
Traceback (most recent call last):
File "C:\PRG\blah\test2.py", line 3, in <module>
sys.stdout.flush()
IOError: [Errno 9] Bad file descriptor
Googled a bit for the solution, but then I've ran your version
(slightly modified) with no errors:
python -c "import sys; print 'test'; sys.stdout.flush();" > test.log
Finally, when I run the .py file with "python test.py > test.log" as
opposed to just "test.py > test.log" or "test > test.log", it works.
I've tried figuring out what the problem is, but from the quick
glance, python that runs .py files and python that's in my path both
are the same "c:\Python27\python.exe".
I'm happy with the workaround however :)
Thanks!
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web