A small library to patch FastAPI to remove deadlock issues when using sync database sessions.
Project description
FastAPI Overflow
When using FastAPI with a synchronous SQLAlchemy session dependency, as per the official example <...>, high loads can lead to temporary deadlocks, timeouts and poor performance.
This is a known issue, for which a PR is open. This library exists to allow users to easily patch the issue and run their code in the mean time.
We provide 3 primary functions:
fastapi_overflow.patchwhich should be called before starting your app in order to patch FastAPI's thread handlingfastapi_overflow.run_in_threadpoolwhich should be used instead ofstarlette.concurrency.run_in_threadpoolorfastapi.concurrency.run_in_threadpoolfastapi_overflow.iterate_in_threadpoolwhich should be used instead ofstarlette.concurrency.iterate_in_threadpoolorfastapi.concurrency.iterate_in_threadpool
Usage
Use it like this:
from fastapi import FastAPI
from fastapi_overflow import patch
patch() # run this before starting your app
app = FastAPI()
Changing the default thread limit
You can increase the number of threads from the default (40) using the fastapi_overflow.set_thread_limit function.
With a very high number of threads you might also want to increase the reserve used to prevent deadlocks from its
default of 1. You will need to add this to your startup events, or lifetime function:
@app.on_event("startup")
def on_startup():
set_thread_limit(limit=..., anti_deadlock_reserve=2)
... # any other setup here
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_overflow-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_overflow-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79750d7268efd06dc53e538c42c6e0bfad5224097c29747f36f9f1ef82caebd3
|
|
| MD5 |
22ebb0e7f4bf4243c4fe5bfc0b0822e9
|
|
| BLAKE2b-256 |
e7965fb1644adc039d254a1c3b339f7431b6b794778bbbfe2bbb3f760f36393e
|
Provenance
The following attestation bundles were made for fastapi_overflow-0.1.0.tar.gz:
Publisher:
ci.yml on olliemath/fastapi-overflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_overflow-0.1.0.tar.gz -
Subject digest:
79750d7268efd06dc53e538c42c6e0bfad5224097c29747f36f9f1ef82caebd3 - Sigstore transparency entry: 1318830391
- Sigstore integration time:
-
Permalink:
olliemath/fastapi-overflow@73c54f32daee633c32f9541aa0481adc14953813 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/olliemath
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@73c54f32daee633c32f9541aa0481adc14953813 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastapi_overflow-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_overflow-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9831bb615d37463cc49691c5d099e78db9cd1d82061dbb7b7d00f6198560e7d8
|
|
| MD5 |
50198d48e824ab2b2d7debae77ae13b0
|
|
| BLAKE2b-256 |
c8f27782e9b3b53742208aa8eb0f51de704b050146bda660b6dc176185730bcb
|
Provenance
The following attestation bundles were made for fastapi_overflow-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on olliemath/fastapi-overflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_overflow-0.1.0-py3-none-any.whl -
Subject digest:
9831bb615d37463cc49691c5d099e78db9cd1d82061dbb7b7d00f6198560e7d8 - Sigstore transparency entry: 1318830463
- Sigstore integration time:
-
Permalink:
olliemath/fastapi-overflow@73c54f32daee633c32f9541aa0481adc14953813 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/olliemath
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@73c54f32daee633c32f9541aa0481adc14953813 -
Trigger Event:
release
-
Statement type: