1
0

write shit

This commit is contained in:
2026-01-06 19:50:45 +08:00
parent 4cdc56a32d
commit 6f4d23868c
6 changed files with 252 additions and 48 deletions

View File

@@ -51,6 +51,10 @@ class PipeOperator:
else:
# POSIX implementation
self.pipe_name = f"/tmp/{name}"
# If there is an existing FIFO file, remove it
if os.path.exists(self.pipe_name):
os.unlink(self.pipe_name)
# Create pipe
try:
os.mkfifo(self.pipe_name)
except OSError as e:
@@ -155,49 +159,3 @@ class PipeOperator:
except OSError as e:
raise RuntimeError(f"Failed to write to named pipe: {e}")
# class PipeServer:
# """
# A convenience class for creating a pipe server that can handle connections in a separate thread.
# """
# def __init__(self, name: str):
# self._name = name
# self._pipe_operator: Optional[PipeOperator] = None
# self._server_thread: Optional[threading.Thread] = None
# self._stop_event = threading.Event()
# def start_server(self, handler_func):
# """
# Start the pipe server in a separate thread.
# :param handler_func: Function to handle the connected pipe (takes PipeOperator as parameter)
# """
# self._server_thread = threading.Thread(target=self._server_worker,
# args=(handler_func, ))
# self._server_thread.start()
# def _server_worker(self, handler_func):
# """Internal method to handle server operations."""
# try:
# # Create pipe server
# pipe_op = PipeOperator(self._name, is_server=True)
# self._pipe_operator = pipe_op
# # Call the handler function with the connected pipe
# handler_func(pipe_op)
# except Exception as e:
# print(f"Error in pipe server: {e}")
# finally:
# if self._pipe_operator:
# self._pipe_operator.close()
# def stop_server(self):
# """Stop the pipe server."""
# self._stop_event.set()
# if self._server_thread:
# self._server_thread.join()
# def get_pipe(self) -> Optional[PipeOperator]:
# """Get the connected pipe operator (only valid after client connects)."""
# return self._pipe_operator