def MakePrivateHandle(handle, replace = 1):
"""Turn an inherited handle into a non inherited one. This avoids the
handle duplication that occurs on CreateProcess calls which can create
uncloseable pipes."""
### Could change implementation to use SetHandleInformation()...
flags = win32con.DUPLICATE_SAME_ACCESS
proc = win32api.GetCurrentProcess()
if replace: flags = flags | win32con.DUPLICATE_CLOSE_SOURCE
newhandle = win32api.DuplicateHandle(proc,handle,proc,0,0,flags)
if replace: handle.Detach() # handle was already deleted by the last call
return newhandle
评论列表
文章目录