Skip to content

Commit

Permalink
feat: Add sleep seconds and thread ID to log message
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Dec 12, 2024
1 parent f4b1dbe commit 633d4e2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions process/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import random
import threading
import time
import warnings
from contextlib import contextmanager
Expand Down Expand Up @@ -110,9 +111,10 @@ def get_or_create(model, data):
except OperationalError as e:
if attempt == MAX_ATTEMPTS:
raise
logger.warning("Deadlock maybe caused by duplicate data, retrying (%s)", e)
# Make the threads retry at different times.
time.sleep(random.randint(1, 5)) # noqa: S311 # non-cryptographic
seconds = random.randint(1, 5) # noqa: S311 # non-cryptographic
logger.warning("Deadlock, retrying after %ds on thread %d\n%s", seconds, threading.get_ident(), e)
time.sleep(seconds)
else:
return obj

Expand Down

0 comments on commit 633d4e2

Please sign in to comment.