1
0

fix while stopper

This commit is contained in:
2026-01-08 20:04:24 +08:00
parent bfaee2028e
commit 886e0caab2
6 changed files with 65 additions and 66 deletions

View File

@@ -68,15 +68,15 @@ class CmdServer:
# Send handshake request to Presenter
self.__pipe_operator.write(CODE_PACKER.pack(ProtocolCode.HANDSHAKE_REQUEST))
# And the payload data
self.__pipe_operator.write(HANDSHAKE_REQUEST_PACKER.pack(
payload.pixel_kind,
payload.width,
payload.height
))
self.__pipe_operator.write(
HANDSHAKE_REQUEST_PACKER.pack(
payload.pixel_kind, payload.width, payload.height
)
)
# Wait for handshake response from Presenter (code 0x62)
code_bytes = self.__pipe_operator.read(CODE_PACKER.size)
(code, ) = CODE_PACKER.unpack(code_bytes)
(code,) = CODE_PACKER.unpack(code_bytes)
if ProtocolCode(code) != ProtocolCode.HANDSHAKE_RESPONSE:
raise RuntimeError("expect handshake response code, but got another")
@@ -84,8 +84,7 @@ class CmdServer:
self.__status = ServerStatus.Running
return
def tick(self, data_receiver: Callable[[], None],
request_stop: bool) -> bool:
def tick(self, data_receiver: Callable[[], None], request_stop: bool) -> bool:
"""
Tick function called every frame to wait for data ready from Presenter and send response.
Returns True if a stop code was received (meaning the process should stop), False otherwise.
@@ -101,7 +100,7 @@ class CmdServer:
while True:
# Wait for code from Presenter
code_bytes = self.__pipe_operator.read(CODE_PACKER.size)
(code, ) = CODE_PACKER.unpack(code_bytes)
(code,) = CODE_PACKER.unpack(code_bytes)
# Analyse code
match ProtocolCode(code):
@@ -109,7 +108,9 @@ class CmdServer:
# Receive data
data_receiver()
# Send data received symbol
self.__pipe_operator.write(CODE_PACKER.pack(ProtocolCode.DATA_RECEIVED))
self.__pipe_operator.write(
CODE_PACKER.pack(ProtocolCode.DATA_RECEIVED)
)
return False
case ProtocolCode.ACTIVELY_STOP:
# Presenter requested stop.
@@ -119,7 +120,6 @@ class CmdServer:
case _:
raise RuntimeError("unexpected protocol code when running")
def __wait_stop(self) -> None:
# Send stop request code
self.__pipe_operator.write(CODE_PACKER.pack(ProtocolCode.STOP_REQUEST))
@@ -128,7 +128,7 @@ class CmdServer:
while True:
# Accept code
code_bytes = self.__pipe_operator.read(CODE_PACKER.size)
(code, ) = CODE_PACKER.unpack(code_bytes)
(code,) = CODE_PACKER.unpack(code_bytes)
# Check whether it is stop response
match ProtocolCode(code):
@@ -138,5 +138,3 @@ class CmdServer:
return
case _:
raise RuntimeError("unexpected protocol code when waiting quit")