Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -217,23 +217,5 @@ app = gr.mount_gradio_app(app, demo, path="/")
|
|
217 |
|
218 |
print("Application startup script finished. Waiting for requests.")
|
219 |
if __name__ == "__main__":
|
220 |
-
import
|
221 |
-
|
222 |
-
def port_is_free(port: int) -> bool:
|
223 |
-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
224 |
-
return s.connect_ex(("0.0.0.0", port)) != 0
|
225 |
-
|
226 |
-
port = int(os.getenv("PORT", 7860))
|
227 |
-
timeout_sec = 30 # 30 秒だけ待つ
|
228 |
-
poll_interval = 2 # 2 秒ごとに再チェック
|
229 |
-
|
230 |
-
t0 = time.time()
|
231 |
-
while not port_is_free(port):
|
232 |
-
waited = time.time() - t0
|
233 |
-
if waited >= timeout_sec:
|
234 |
-
raise RuntimeError(f"Port {port} is still busy after {timeout_sec}s")
|
235 |
-
print(f"⚠️ Port {port} busy, retrying in {poll_interval}s …")
|
236 |
-
time.sleep(poll_interval)
|
237 |
-
|
238 |
-
# 空いたら起動
|
239 |
-
uvicorn.run(app, host="0.0.0.0", port=port, workers=1, log_level="info")
|
|
|
217 |
|
218 |
print("Application startup script finished. Waiting for requests.")
|
219 |
if __name__ == "__main__":
|
220 |
+
import uvicorn
|
221 |
+
uvicorn.run(app, host="0.0.0.0", port=7860, workers=1, log_level="info")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|