[tahoe-lafs-trac-stream] [tahoe-lafs] #1232: Unicode stdout/stderr replacement on Windows fails to print large strings

tahoe-lafs trac at tahoe-lafs.org
Sun Mar 27 07:13:00 PDT 2011


#1232: Unicode stdout/stderr replacement on Windows fails to print large strings
----------------------------+-----------------------------------------------
     Reporter:  davidsarah  |       Owner:  davidsarah                       
         Type:  defect      |      Status:  closed                           
     Priority:  major       |   Milestone:  1.8.1                            
    Component:  code        |     Version:  1.8.0                            
   Resolution:  fixed       |    Keywords:  unicode regression easy news-done
Launchpad Bug:              |  
----------------------------+-----------------------------------------------

Comment (by davidsarah):

 It is possible for calls to the console functions by multiple threads to
 cause this error even when the amount written in each call is limited to
 10000 characters (20000 bytes). However Tahoe-LAFS is single-threaded
 (almost; there are a few uses of {{{deferToThread}}}, but I don't think we
 print from those threads), so this shouldn't affect us. I'm pointing it
 out here because I know this ticket is referenced from tickets in other
 projects.

 {{{
 # Warning: this test may DoS your system.

 from threading import Thread
 import sys
 from ctypes import WINFUNCTYPE, windll, POINTER, byref
 from ctypes.wintypes import BOOL, HANDLE, DWORD, LPVOID, LPCVOID

 GetStdHandle = WINFUNCTYPE(HANDLE, DWORD)(("GetStdHandle",
 windll.kernel32))
 WriteFile = WINFUNCTYPE(BOOL, HANDLE, LPCVOID, DWORD, POINTER(DWORD),
 LPVOID) \
                         (("WriteFile", windll.kernel32))
 GetLastError = WINFUNCTYPE(DWORD)(("GetLastError", windll.kernel32))
 STD_OUTPUT_HANDLE = DWORD(-11)
 INVALID_HANDLE_VALUE = DWORD(-1).value

 hStdout = GetStdHandle(STD_OUTPUT_HANDLE)
 assert hStdout is not None and hStdout != INVALID_HANDLE_VALUE

 LENGTH = 20000 #bytes
 THREADS = 10

 data = b'\x08'*LENGTH

 def run():
     n = DWORD(0)
     while True:
         ret = WriteFile(hStdout, data, LENGTH, byref(n), None)
         if ret == 0 or n.value != LENGTH:
             print("WriteFile returned %d, bytes written = %d, last error =
 %d"
                   % (ret, n.value, GetLastError()))
             sys.exit(1)

 for i in range(THREADS):
     Thread(target=run).start()
 }}}

-- 
Ticket URL: <http://tahoe-lafs.org/trac/tahoe-lafs/ticket/1232#comment:8>
tahoe-lafs <http://tahoe-lafs.org>
secure decentralized storage


More information about the tahoe-lafs-trac-stream mailing list