@@ -51,6 +51,20 @@ def find_proton(steam_path: Path) -> Path | None:
5151 return None
5252
5353
54+ def wait_for_port (host : str , port : int , timeout : float = 30.0 ) -> bool :
55+ """Wait for port to be ready to accept connections."""
56+ import socket
57+
58+ start = time .time ()
59+ while time .time () - start < timeout :
60+ try :
61+ with socket .create_connection ((host , port ), timeout = 1 ):
62+ return True
63+ except (ConnectionRefusedError , OSError ):
64+ time .sleep (0.5 )
65+ return False
66+
67+
5468def kill_port (port : int ):
5569 """Kill processes using the specified port."""
5670 print (f"Killing processes on port { port } ..." )
@@ -156,10 +170,12 @@ def start(args):
156170 stderr = subprocess .STDOUT ,
157171 )
158172
159- # Wait and verify process started
160- time .sleep (3 )
161- if process .poll () is not None :
162- print (f"ERROR: Balatro failed to start. Check { log_file } " )
173+ # Wait for port to be ready
174+ print (f"Waiting for port { args .port } to be ready..." )
175+ if not wait_for_port (args .host , args .port , timeout = 30 ):
176+ print (f"ERROR: Port { args .port } not ready after 30s. Check { log_file } " )
177+ if process .poll () is not None :
178+ print ("Balatro process has exited." )
163179 sys .exit (1 )
164180
165181 print ("Balatro started successfully!" )
0 commit comments