#2052 closed defect (fixed)
"Bad file descriptor" error setting binary I/O on Windows
Reported by: | Juanma Barranquero | Owned by: | Matthew Good |
---|---|---|---|
Priority: | low | Milestone: | 0.9 |
Component: | general | Version: | devel |
Severity: | normal | Keywords: | hooks windows |
Cc: | gytis@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
(This has been discussed on the mailing list, but AFAICS there's no ticket for it).
The following code from env.py originates in changes [412:413], commited to fix #244:
try: # Use binary I/O on Windows import msvcrt, sys msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) except ImportError: pass
However, it has the side effect that it bombs out with
File "C:\bin\python\lib\site-packages\trac\env.py", line 70, in __init__ msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) IOError: [Errno 9] Bad file descriptor
on some cases (Windows hooks, running as a service, etc.), as apparently there are no stdin
/stdout
filehandles available.
Attachments (0)
Change History (7)
comment:1 by , 19 years ago
Cc: | added |
---|
comment:2 by , 19 years ago
Milestone: | → 0.9 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Would trapping the IOError be OK?
- except ImportError: + except (ImportError, IOError, ValueError):
ValueError
added for good mesure, it's what one gets
if the files are closed.
comment:3 by , 19 years ago
Trapping IOError
is what I do, and it works for my use case (calling trac-post-commit-hook from the post-commit hook). I don't know whether this fix works for the other use cases (but presumably it will, at least on the running-as-service case, where standard handles are not needed or used).
comment:4 by , 19 years ago
Wouldn't it be better to do this whole binary-io-on-win32 thing in the CGI front-end?
comment:6 by , 19 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
Since this involves similar issues with the stdin/stdout mode to #2066 I'll combine the two to provide a single method in the CGI front-end to make sure the modes are set correctly for the applicable platform.
comment:7 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Ok, this should be fixed in [2260]
I had this problem with SVN commit hooks, when using mod_dav_svn. The solution (i would rather call it a hack) was to open temporary files for stdin and stdout.