New submission from Karthk Rajagopalan:

Please download and extract the archive. Run - 


you will notice 'invalid handle' error on duplicating STD_INPUT_HANDLE in 
python. This is observed in Windows XP SP3. Vista SP2 and higher platforms 
doesn't show this failure when I checked.

"" spawn a python process "" using CREATE_NEW_PROCESS_GROUP flag. 
Before it does, it close STDIN and create a listening socket. Perl under the 
hood, convert the socket handle to file descriptor using open_osfhandle(..) 
call. When it does this, the C runtime set the standard input handle to this 
descriptor  for console app. [ See msvcr* osfinfo.c code - SetStdHandle( 
STD_INPUT_HANDLE, (HANDLE)value )  ]. As a result, when you get the 
STD_INPUT_HANDLE, you will get the new one. Duplicating this handle, hence 
throw the invalid handle error in Windows XP SP3. 

When I looked at MSDN for DuplicateHandle(..), it is mentioned not to duplicate 
socket handle using this call. So I suspect something going wrong in XP 
platform. To fix this issue, I have come up with a patch - python-2143_patch. 
Please take a look and let me know your comments.


components: Windows
messages: 175416
nosy: kartlee05
priority: normal
severity: normal
status: open
title: throw "The handle is invalid" error on duplicating the 
type: behavior
versions: Python 2.7
Added file:

Python tracker <>
Python-bugs-list mailing list

Reply via email to