@@ -393,11 +393,13 @@ def __enter__(self) -> Self:
393393
394394 # プロセスを起動
395395 try :
396+ # 注意: stderr=subprocess.PIPE に変更すると Windows でテストが通らなくなる
397+ # Windows ではパイプバッファが小さく、stderr を定期的に読み取らないと
398+ # バッファがいっぱいになってプロセスがブロックされる可能性がある
396399 self .process = subprocess .Popen (
397400 cmd ,
398401 stdout = subprocess .DEVNULL ,
399- stderr = subprocess .PIPE ,
400- text = True ,
402+ stderr = subprocess .DEVNULL ,
401403 )
402404 print (f"Started sumomo process with PID: { self .process .pid } " )
403405 except FileNotFoundError :
@@ -420,17 +422,7 @@ def __enter__(self) -> Self:
420422 if self .process and platform .system ().lower () == "windows" :
421423 poll_result = self .process .poll ()
422424 if poll_result is not None :
423- # プロセスが終了していたらエラーメッセージを表示
424- stderr_output = ""
425- if self .process .stderr :
426- try :
427- stderr_output = self .process .stderr .read ()
428- except Exception :
429- pass
430- raise RuntimeError (
431- f"sumomo.exe exited unexpectedly with code { poll_result } \n "
432- f"Stderr: { stderr_output } "
433- )
425+ raise RuntimeError (f"sumomo.exe exited unexpectedly with code { poll_result } " )
434426
435427 # HTTP クライアントを作成
436428 self ._http_client = httpx .Client (timeout = 10.0 )
@@ -817,16 +809,7 @@ def get_stats(self) -> list[dict[str, Any]]:
817809 # Windows の場合、プロセスが生きているか確認
818810 if self .process and platform .system ().lower () == "windows" :
819811 if self .process .poll () is not None :
820- stderr_output = ""
821- if hasattr (self .process , "stderr" ) and self .process .stderr :
822- try :
823- stderr_output = self .process .stderr .read ()
824- except :
825- pass
826- raise RuntimeError (
827- f"sumomo.exe has crashed (exit code: { self .process .returncode } )\n "
828- f"Stderr: { stderr_output } "
829- )
812+ raise RuntimeError (f"sumomo.exe has crashed (exit code: { self .process .returncode } )" )
830813
831814 try :
832815 # http_host は 127.0.0.1 固定
@@ -837,15 +820,8 @@ def get_stats(self) -> list[dict[str, Any]]:
837820 # Windows の場合、エラー時にプロセスの状態を確認
838821 if self .process and platform .system ().lower () == "windows" :
839822 if self .process .poll () is not None :
840- stderr_output = ""
841- if hasattr (self .process , "stderr" ) and self .process .stderr :
842- try :
843- stderr_output = self .process .stderr .read ()
844- except :
845- pass
846823 raise RuntimeError (
847824 f"sumomo.exe crashed while getting stats (exit code: { self .process .returncode } )\n "
848- f"Stderr: { stderr_output } \n "
849825 f"Original error: { e } "
850826 )
851827 raise
0 commit comments