本文へスキップ
hdknr blog
戻る

MPTT tree_id

更新日:

MPTT Tree ID

分散ロック

from django.core.cache import cache

with cache.lock("somekey"):
    do_some_thing()

redis-py:

デッドロック

import django.db.backends.utils
from django.db import OperationalError
import time

original = django.db.backends.utils.CursorWrapper.execute

def execute_wrapper(*args, **kwargs):
    attempts = 0
    while attempts < 3:
        try:
            return original(*args, **kwargs)
        except OperationalError as e:
            code = e.args[0]
            if attempts == 2 or code != 1213:
                raise e
            attempts += 1
            time.sleep(0.2)

django.db.backends.utils.CursorWrapper.execute = execute_wrapper


前の記事
RDS バーストバランス
次の記事
Redis キーの作成時刻