fix bug
This commit is contained in:
@@ -92,10 +92,10 @@ class CmdServer:
|
||||
if self.__status != ServerStatus.Running:
|
||||
raise RuntimeError("unexpected server status")
|
||||
|
||||
# If there is stop requested, we post it first and return
|
||||
# If there is stop requested from us,
|
||||
# we order Presenter exit and enter next step.
|
||||
if request_stop:
|
||||
self.__wait_stop()
|
||||
return True
|
||||
self.__pipe_operator.write(CODE_PACKER.pack(ProtocolCode.STOP_REQUEST))
|
||||
|
||||
while True:
|
||||
# Wait for code from Presenter
|
||||
@@ -115,26 +115,12 @@ class CmdServer:
|
||||
case ProtocolCode.ACTIVELY_STOP:
|
||||
# Presenter requested stop.
|
||||
# Agree with it, send code and wait response
|
||||
self.__wait_stop()
|
||||
return True
|
||||
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))
|
||||
|
||||
# Wait stop response code
|
||||
while True:
|
||||
# Accept code
|
||||
code_bytes = self.__pipe_operator.read(CODE_PACKER.size)
|
||||
(code,) = CODE_PACKER.unpack(code_bytes)
|
||||
|
||||
# Check whether it is stop response
|
||||
match ProtocolCode(code):
|
||||
self.__pipe_operator.write(
|
||||
CODE_PACKER.pack(ProtocolCode.STOP_REQUEST)
|
||||
)
|
||||
case ProtocolCode.STOP_RESPONSE:
|
||||
# Set self status and return
|
||||
self.__status = ServerStatus.Stop
|
||||
return
|
||||
return True
|
||||
case _:
|
||||
raise RuntimeError("unexpected protocol code when waiting quit")
|
||||
raise RuntimeError("unexpected protocol code when running")
|
||||
|
||||
@@ -27,4 +27,4 @@ url = "https://download.pytorch.org/whl/cu126"
|
||||
explicit = true
|
||||
|
||||
[too.ruff]
|
||||
line-length = 88
|
||||
line-length = 130
|
||||
|
||||
Reference in New Issue
Block a user