fix while stopper
This commit is contained in:
@@ -24,7 +24,7 @@ class PipeOperator:
|
||||
def __init__(self, name: str):
|
||||
"""
|
||||
Initialize the PipeOperator.
|
||||
|
||||
|
||||
:param name: Name of the pipe
|
||||
:param is_server: True if this instance should create the pipe (server), False if connecting to existing pipe (client)
|
||||
"""
|
||||
@@ -35,13 +35,14 @@ class PipeOperator:
|
||||
self.pipe_handle = win32pipe.CreateNamedPipe(
|
||||
self.pipe_name,
|
||||
win32pipe.PIPE_ACCESS_DUPLEX,
|
||||
win32pipe.PIPE_TYPE_BYTE | win32pipe.PIPE_READMODE_BYTE
|
||||
win32pipe.PIPE_TYPE_BYTE
|
||||
| win32pipe.PIPE_READMODE_BYTE
|
||||
| win32pipe.PIPE_WAIT,
|
||||
1, # Number of pipe instances
|
||||
65536, # Output buffer size
|
||||
65536, # Input buffer size
|
||||
0, # Default timeout
|
||||
None # Security attributes
|
||||
None, # Security attributes
|
||||
)
|
||||
if self.pipe_handle == win32file.INVALID_HANDLE_VALUE:
|
||||
raise RuntimeError("Failed to create named pipe.")
|
||||
@@ -78,7 +79,7 @@ class PipeOperator:
|
||||
def read(self, size: int) -> bytes:
|
||||
"""
|
||||
Read data from the pipe. This is a blocking operation.
|
||||
|
||||
|
||||
:param size: Number of bytes to read
|
||||
:return: Bytes read from the pipe
|
||||
"""
|
||||
@@ -96,8 +97,7 @@ class PipeOperator:
|
||||
data: Any
|
||||
(hr, data) = win32file.ReadFile(self.pipe_handle, size)
|
||||
if hr != 0: # Error occurred
|
||||
raise RuntimeError(
|
||||
f"Failed to read from pipe, error code: {hr}")
|
||||
raise RuntimeError(f"Failed to read from pipe, error code: {hr}")
|
||||
data = bytes(data)
|
||||
if len(data) != size:
|
||||
raise RuntimeError(
|
||||
@@ -128,7 +128,7 @@ class PipeOperator:
|
||||
def write(self, data: bytes) -> None:
|
||||
"""
|
||||
Write data to the pipe. This is a blocking operation.
|
||||
|
||||
|
||||
:param data: Data to write to the pipe
|
||||
"""
|
||||
if len(data) == 0:
|
||||
@@ -147,8 +147,7 @@ class PipeOperator:
|
||||
total_written = 0
|
||||
while total_written < len(data):
|
||||
try:
|
||||
bytes_written = os.write(self.pipe_handle,
|
||||
data[total_written:])
|
||||
bytes_written = os.write(self.pipe_handle, data[total_written:])
|
||||
total_written += bytes_written
|
||||
except OSError as e:
|
||||
raise RuntimeError(f"Failed to write to named pipe: {e}")
|
||||
|
||||
Reference in New Issue
Block a user