would like a infinite retry. but infinite is too scaring while counter < 1000: counter += 1 try: with transaction.atomic(): cursor = connections[‘your_db’].cursor() cursor.execute('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE') # Your DB Operations except OperationalError: time.sleep(counter) # to avoid retry in a very short interval continue 1 2 3
would like a infinite retry. but infinite is too scaring while counter < 1000: counter += 1 try: with transaction.atomic(): cursor = connections[‘your_db’].cursor() cursor.execute('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE') # Your DB Operations except OperationalError: time.sleep(counter) # to avoid retry in a very short interval continue 1 2 3 1 the context manager will start a transaction and commit after exists the block
would like a infinite retry. but infinite is too scaring while counter < 1000: counter += 1 try: with transaction.atomic(): cursor = connections[‘your_db’].cursor() cursor.execute('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE') # Your DB Operations except OperationalError: time.sleep(counter) # to avoid retry in a very short interval continue 1 2 3 2 change the isolation level to serializable
would like a infinite retry. but infinite is too scaring while counter < 1000: counter += 1 try: with transaction.atomic(): cursor = connections[‘your_db’].cursor() cursor.execute('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE') # Your DB Operations except OperationalError: time.sleep(counter) # to avoid retry in a very short interval continue 1 2 3 3 latter transaction will meets Operational Error, usually it needs retry
https://github.com/Xof/django-pglocks lock_id = "Any String You Want" with advisory_lock(lock_id=lock_id, shared=False): pass # Your DB Operations Here