Skip to content

Commit 8c3f73e

Browse files
committed
Mise à jour pour utiliser un autre port
1 parent 5553eb2 commit 8c3f73e

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

.github/workflows/build-ui.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
python -m PyInstaller --name ok_computer_ui-${{ matrix.os }} --onefile \
3434
--add-data "ui/templates${SEP}templates" \
3535
--add-data "ui/static${SEP}static" \
36+
--collect-submodules flask \
37+
--hidden-import socket \
3638
ui/app.py
3739
shell: bash
3840

ui/app.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import requests
55
from pathlib import Path
6+
import multiprocessing
7+
import socket
68

79
BASE_DIR = Path(__file__).resolve().parents[1]
810
ENV_LOCAL = BASE_DIR / '.env.local'
@@ -172,5 +174,23 @@ def api_search():
172174
def static_files(p):
173175
return send_from_directory(os.path.join(os.path.dirname(__file__),'static'), p)
174176

177+
def is_port_in_use(port):
178+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
179+
return s.connect_ex(('localhost', port)) == 0
180+
175181
if __name__=='__main__':
176-
app.run(host='0.0.0.0', port=5000, debug=True)
182+
multiprocessing.freeze_support()
183+
184+
port = int(os.environ.get('PORT', 5000))
185+
if is_port_in_use(port):
186+
print(f" * Port {port} is in use. Trying to find another port...")
187+
if port == 5000:
188+
port = 5001
189+
while is_port_in_use(port):
190+
port += 1
191+
if port > 5010: # Limit searches
192+
break
193+
194+
debug = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true'
195+
print(f" * Starting server on http://localhost:{port} (debug={debug})")
196+
app.run(host='0.0.0.0', port=port, debug=debug)

ui/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ esac
2424
python -m PyInstaller --name "$NAME" --onefile \
2525
--add-data "templates${SEP}templates" \
2626
--add-data "static${SEP}static" \
27+
--collect-submodules flask \
28+
--hidden-import socket \
2729
app.py
2830

2931
echo "Built: dist/$NAME"

0 commit comments

Comments
 (0)