Fix win32pipe.WaitNamedPipe throw exception in windows container.

Signed-off-by: Renlong Tu <rentu@microsoft.com>
This commit is contained in:
rentu 2019-08-30 09:35:46 +01:00
parent 8acd2c3d08
commit 015f44d8f8
1 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import functools import functools
import time
import io import io
import six import six
@ -9,7 +10,7 @@ cERROR_PIPE_BUSY = 0xe7
cSECURITY_SQOS_PRESENT = 0x100000 cSECURITY_SQOS_PRESENT = 0x100000
cSECURITY_ANONYMOUS = 0 cSECURITY_ANONYMOUS = 0
RETRY_WAIT_TIMEOUT = 10000 MAXIMUM_RETRY_COUNT = 10
def check_closed(f): def check_closed(f):
@ -46,8 +47,7 @@ class NpipeSocket(object):
self._closed = True self._closed = True
@check_closed @check_closed
def connect(self, address): def connect(self, address, retry_count=0):
win32pipe.WaitNamedPipe(address, self._timeout)
try: try:
handle = win32file.CreateFile( handle = win32file.CreateFile(
address, address,
@ -65,8 +65,10 @@ class NpipeSocket(object):
# Another program or thread has grabbed our pipe instance # Another program or thread has grabbed our pipe instance
# before we got to it. Wait for availability and attempt to # before we got to it. Wait for availability and attempt to
# connect again. # connect again.
win32pipe.WaitNamedPipe(address, RETRY_WAIT_TIMEOUT) retry_count = retry_count + 1
return self.connect(address) if (retry_count < MAXIMUM_RETRY_COUNT):
time.sleep(1)
return self.connect(address, retry_count)
raise e raise e
self.flags = win32pipe.GetNamedPipeInfo(handle)[0] self.flags = win32pipe.GetNamedPipeInfo(handle)[0]