Alternative to python -u for binary upload to cgi on windows?
cameron.walsh at gmail.com
cameron.walsh at gmail.com
Sat Dec 22 20:44:58 EST 2007
On Dec 14, 6:58 pm, Cameron Walsh <cameron.wa... at gmail.com> wrote:
> Hi all,
>
> Using a pythoncgiscript such as the one below to handle uploaded
> binary files will end up with atruncatedfile (truncates when it hits
> ^Z) on Windows systems. On linux systems the code works and the file is
> nottruncated.
>
> One solution for Windows is to use the -u flag, i.e.
> #!C:\Python\python.exe -u
>
> Is there another fix that doesn't require python to be run in unbuffered
> mode? What performance hits would I expect for running in unbuffered mode?
Answer to the first part:
import msvcrt, sys, os
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
# other problems may also be fixed with:
# msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
Cameron.
More information about the Python-list
mailing list