Skip to content

Commit

Permalink
fix(api): use Waitress for Windows bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Apr 11, 2023
1 parent 76860f6 commit 9a2f35e
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions api/entry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import multiprocessing
import os
import threading
import waitress
import webbrowser

def script_method(fn, _rcb=None):
Expand All @@ -15,24 +16,37 @@ def script(obj, optimize=True, _frames_up=0, _rcb=None):
if __name__ == '__main__':
multiprocessing.freeze_support()
try:
# convert the models
from onnx_web.convert.__main__ import main as convert
print("converting models to ONNX")
print("downloading and converting models to ONNX")
convert()

# create the server and load the config
from onnx_web.main import main
app, pool = main()

# launch the image workers
print("starting image workers")
pool.start()

# launch the API server
print("starting API server")
app.run("0.0.0.0", 5000, debug=False)
server = waitress.create_server(app, host="0.0.0.0", port=5000)
thread = threading.Thread(target=server.run)
thread.daemon = True
thread.start()

# launch the user's web browser
print("opening web browser")
url = "http://127.0.0.1:5000"
webbrowser.open_new_tab(f"{url}?api={url}")

# wait for enter and exit
input("press enter to quit")
server.close()
thread.join(1.0)

print("shutting down image workers")
pool.join()
except Exception as e:
print(e)
finally:
os.system("pause")

0 comments on commit 9a2f35e

Please sign in to comment.