File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 33import os
44import requests
55from pathlib import Path
6+ import multiprocessing
7+ import socket
68
79BASE_DIR = Path (__file__ ).resolve ().parents [1 ]
810ENV_LOCAL = BASE_DIR / '.env.local'
@@ -172,5 +174,23 @@ def api_search():
172174def 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+
175181if __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 )
Original file line number Diff line number Diff line change 2424python -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
2931echo " Built: dist/$NAME "
You can’t perform that action at this time.
0 commit comments