B
B
Bleno2021-01-22 18:47:04
Flask
Bleno, 2021-01-22 18:47:04

What if gunicorn doesn't close all child threads?

Given: Python 3.7, flask webserver under gunicorn.

For each request, gunicorn creates a separate thread (threading module), but for some reason gunicorn does not close all threads after the code has been executed. The result is this picture:

[item.name for item in threading.enumerate()]
['MainThread', 'WorkerThread1', 'WorkerThread2', 'WorkerThread3', 'WorkerThread4', 'WorkerThread5', 'WorkerThread6', 'WorkerThread7', 'WorkerThread8', 'WorkerThread9', 'WorkerThread10', 'WorkerThread11', 'WorkerThread12', 'WorkerThread13', 'WorkerThread14', 'WorkerThread15', 'WorkerThread16', 'WorkerThread17', ...

Over time, these unclosed threads pile up and end up putting a lot of load on the CPU.

Why don't they close? How to fix it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question