I've got a fairly complicated python/ flask backend (server.py) that is working well and ready for deployment. I am trying to package it up for deployment as an executable with
pyinstaller --recursive-copy-metadata transformers --copy-metadata numpy --copy-metadata pandas --copy-metadata flask --copy-metadata flask_cors --copy-metadata nltk \
--copy-metadata bertopic \
--copy-metadata numba \
--copy-metadata waitress \
--collect-submodules server_classes.models \
--collect-submodules server_classes.post_data_handler \
--onefile \
--clean \
--add-data "data/ground_truth_post.csv:data" \
--add-data "data/saved_data.json:data" \
--add-data "data/new_file.csv:data" \
--add-data "server_classes/saved_models/tokenizer:saved_models" \
--add-data "server_classes/saved_models/sentiment_model:saved_models" \
--add-data "server_classes/saved_models/topic_model:saved_models" \
--add-data "numba_cache:numba_cache" \
server.py
This works functionally, but the executable version of the server keeps tripping over itself as it spawns a number of processes at once instead of just one server. They continue to run even after I ctrl c the program until I check ps and kill all instances by their process IDs. I get one error at runtime that I think could be causing the server to relaunch itself multiple times, but I'm not totally sure what it is or how to fix it.
Traceback (most recent call last):
File "server.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "server_classes/post_data_handler.py", line 5, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "server_classes/models.py", line 4, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "bertopic/__init__.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "bertopic/_bertopic.py", line 38, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "umap/__init__.py", line 2, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "umap/umap_.py", line 41, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "umap/layouts.py", line 40, in <module>
File "numba/core/decorators.py", line 234, in wrapper
File "numba/core/dispatcher.py", line 863, in enable_caching
File "numba/core/caching.py", line 601, in __init__
File "numba/core/caching.py", line 333, in __init__
File "numba/core/caching.py", line 247, in from_function
File "numba/core/caching.py", line 235, in __init__
File "numba/core/caching.py", line 145, in get_suitable_cache_subpath
File "posixpath.py", line 383, in abspath
My server is called as such in server.py (works fine as a python file).
<some imports for logic of server>
from flask import Flask
from flask import request
from flask_cors import CORS
from waitress import serve
app = Flask(__name__)
CORS(app)
.
. server code
.
if __name__ == '__main__':
serve(app, host='localhost', port=5000)
I've tried quite a few things including conditionally checking that port 5000 is not in use before launching. I think it could be an error in the way I'm packaging the app, but everything is functional so it is hard to tell what could be packaged wrong. Thanks in advance.