Error with sys.stdout.write - Directories with spaces

7 views
Skip to first unread message

TL

unread,
Jan 21, 2009, 12:18:35 PM1/21/09
to leo-editor
If I load a Leo file from a directory path with a space character in
WinXP, I receive the following error during the Vim emulation key
remapping:
...
redefining shortcut Ctrl+bracketleft from set-command-state (all)
to unindent-region (all)
redefining shortcut Ctrl+y from scroll-outline-up-line (all) to
yank (all)
Traceback (most recent call last):
File "C:\_Proj\Leo\leo-editor\leo\core\leoGlobals.py", line 3077, in
pr
sys.stdout.write(s+'\n')
IOError: [Errno 9] Bad file descriptor
redefining shortcut Ctrl+y from scroll-up (all) to yank
(all)
setting HOME to os.getenv('USER'): 'TL'
...

If I load the same file from a directory path without spaces, I don't
get the error.

In addition to requesting that it be fixed, can someone tell me how to
view the text sent to stdout when running the 'pythonw' command from a
dos batch file. I would have expected that, when I don't see the
error, that the text sent to stdout would be displayed in the dos
window.

TL

Edward K. Ream

unread,
Jan 22, 2009, 8:36:22 AM1/22/09
to leo-e...@googlegroups.com
On Wed, Jan 21, 2009 at 11:18 AM, TL <t...@tltools.net> wrote:

Traceback (most recent call last):
 File "C:\_Proj\Leo\leo-editor\leo\core\leoGlobals.py", line 3077, in pr
   sys.stdout.write(s+'\n')
IOError: [Errno 9] Bad file descriptor

Strange.  I find it impossible to believe that adding a space character to s will cause sys.stdout.write(s+'\n') to fail.

Presumably something else is happening.  Maybe sys.stdout has been somehow redefined?  This is the only way I can see to generate a Bad File descriptor.

Anyway, I'll look into this asap.

Edward

TL

unread,
Jan 22, 2009, 11:54:36 PM1/22/09
to leo-editor
> I find it impossible to believe that adding a space character to s
> will cause sys.stdout.write(s+'\n') to fail.

The problem is not related to the string being written to stdout. The
problem occurs if the Leo file being loaded is located in a directory
containing a space.

I have found a workaround by redirecting stdout to a log file when
launching pythonw from a dos batch file as follows:

cd c:\Leo\leo-editor
Pythonw leo\core\runLeo.py %1 > Log.txt

When the Leo file is located in a directory with spaces, the Log.txt
file is written to immediately during Leo startup. When the Leo file
is located in a directory without spaces, the Log.txt file is empty
after the Leo startup code has completed but is being cached
somewhere. Once I start working with the Leo file, more text is sent
to stdout and the cache is written to the Log.txt file. I have no
idea why a space in the directory name has an effect on the caching of
output to stdout.

Note: I have added an entry to bug report #319684 - "Vim plugin error
- print ('vim_cmd: %s' % vim_cmd)" requesting that the bug be closed.
The print statement added to the Vim plugin was flushing the stdout
cache and causing the error reported in this forum post.

TL

Edward K. Ream

unread,
Jan 23, 2009, 8:54:52 AM1/23/09
to leo-e...@googlegroups.com
On Thu, Jan 22, 2009 at 10:54 PM, TL <t...@tltools.net> wrote:


The problem is not related to the string being written to stdout. The problem occurs if the Leo file being loaded is located in a directory containing a space.

Interesting.  I'll run some tests.

I have found a workaround

Thanks.  However, a workaround doesn't clear the bug.

Note: I have added an entry to bug report...requesting that the bug be closed.

I don't that that would be a good idea.  Something should be done.

The print statement added to the Vim plugin was flushing the stdout cache and causing the error reported in this forum post.

Thanks for this clarification.

Edward

Edward K. Ream

unread,
Jan 30, 2009, 6:51:22 PM1/30/09
to leo-editor
On Jan 21, 11:18 am, TL <t...@tltools.net> wrote:
> If I load a Leo file from a directory path with a space character in
> WinXP, I receive the following error during the Vim emulation key
> remapping:
> ...
> redefining shortcut     Ctrl+bracketleft from set-command-state (all)
> to unindent-region (all)
> redefining shortcut     Ctrl+y from scroll-outline-up-line (all) to
> yank (all)
> Traceback (most recent call last):
>   File "C:\_Proj\Leo\leo-editor\leo\core\leoGlobals.py", line 3077, in
> pr
>     sys.stdout.write(s+'\n')
> IOError: [Errno 9] Bad file descriptor
> redefining shortcut               Ctrl+y from scroll-up (all) to yank
> (all)
> setting HOME to os.getenv('USER'): 'TL'
> ...
>
> If I load the same file from a directory path without spaces, I don't
> get the error.

I just performed this and all is well.

Let us be clear. The traceback clearly indicates that it is indeed
the line:

sys.stdout.write(s+'\n')

that is failing.

I suspect that sys.stdout has been broken and that sys.stdout is
attempting to writeto an invalid file descriptor. I suggest doing the
following:

1. Replace sys.stdout with sys.__stdout__. This will use an unbroken
stream. It should make the problem go away.

2. If the problem does go away, try printing the value of sys.stdout
itself. This should tell you what stream is being used.

Edward

TL

unread,
Jan 31, 2009, 9:59:58 AM1/31/09
to leo-editor
> I suspect that sys.stdout has been broken and that sys.stdout is
> attempting to writeto an invalid file descriptor.

I agree. I solved the problem specifying an implicit redirect of
stdout to a file. See my reply above from Jan 22.

Regards,
TL
Reply all
Reply to author
Forward
0 new messages