fix: start processing thread

This commit is contained in:
Akbar Rahman 2023-12-27 23:48:37 +00:00
parent 2b844a899f
commit 109e06a5d6
Signed by: alvierahman90
GPG Key ID: 6217899F07CA2BDF
6 changed files with 12 additions and 9 deletions

View File

@ -1,3 +1,4 @@
env env
.git .git
**/__pycache__ **/__pycache__
q

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
env env
**/__pycache__ **/__pycache__
q

View File

@ -13,4 +13,4 @@ RUN apt update && apt install -y ffmpeg libsm6 libxext6
COPY src . COPY src .
COPY best.pt /best.pt COPY best.pt /best.pt
CMD [ "gunicorn", "-b 0.0.0.0:80", "app:app" ] CMD [ "gunicorn", "-b 0.0.0.0:80", "--workers", "1", "app:app" ]

View File

@ -5,4 +5,4 @@ services:
build: . build: .
restart: unless-stopped restart: unless-stopped
ports: ports:
- 8759:8000 - 8759:80

View File

@ -10,7 +10,7 @@
<img id="img" src="" /> <img id="img" src="" />
<p id="statusline">submit an image to get started!</p> <p id="statusline">submit an image to get started!</p>
<form id="form" action="http://localhost:5000/submit" method="post"> <form id="form" action="http://localhost:8759/submit" method="post">
<input type="file" id="job" name="image" accept="image/png,image/jpeg" /><br> <input type="file" id="job" name="image" accept="image/png,image/jpeg" /><br>
<button type="submit" id="submit">submit</button> <button type="submit" id="submit">submit</button>
</form> </form>
@ -38,11 +38,11 @@
console.log(id); console.log(id);
while (true) { while (true) {
const resp = await fetch('http://localhost:5000/state/' + id); const resp = await fetch('http://localhost:8759/state/' + id);
const state = (await resp.json()).state; const state = (await resp.json()).state;
statusline.innerHTML = state; statusline.innerHTML = state;
if (state == "READY") { if (state == "READY") {
img.src = 'http://localhost:5000/result/' + id img.src = 'http://localhost:8759/result/' + id
return; return;
} }
} }

View File

@ -44,7 +44,7 @@ def process():
print("waiting for/getting job") print("waiting for/getting job")
job = q.get() job = q.get()
filepath = root.joinpath(job) filepath = root.joinpath(job)
print("got job") print("got job", flush=True)
state[job] = { state[job] = {
'state': QUEUE_STATE_PROCESSING, 'state': QUEUE_STATE_PROCESSING,
} }
@ -65,6 +65,10 @@ def process():
last = time.time() last = time.time()
p = Thread(target=process)
p.start()
@app.route("/submit", methods=['POST']) @app.route("/submit", methods=['POST'])
def render(): def render():
id = str(uuid.uuid4()) id = str(uuid.uuid4())
@ -87,7 +91,4 @@ def get_result(i):
if __name__ == '__main__': if __name__ == '__main__':
p = Thread(target=process)
p.start()
app.run(debug=True) app.run(debug=True)
p.join()