Skip to content Skip to sidebar Skip to footer

Atomic Insertion In Flask

I have a problem to achieve the following in Flask and SQLAlchemy: I have a kind of blog application written in Flask where a user can write textblocks. So I have a user model and

Solution 1:

If you are using gunicorn, then you can set preload_app = True in your gunicorn.conf. This ensures that a lock is shared across workers (i.e. processes).

A more webserver agnostic solution would be to use NamedAtomicLock. This is a great package that creates an operating system global lock. So a lock can be shared across processes. A lock creates an empty folder in a specified directory which is used as shared resource. Since creating and deleting direcories is an atomic operation according to the POSIX standard, this mechanism allows to lock across processes. I am not sure if it works on non-UNIX machines, e.g. Windows.

Post a Comment for "Atomic Insertion In Flask"