के लिए डेडलॉक पर पुनः प्रयास करें मैंने अभी कुछ समय खोजा है और मेरी समस्या का समाधान नहीं मिला है। हम कई बार हमारे परियोजना के लिए MySQL के साथ संयोजन के रूप में SQLAlchemy का उपयोग कर रहे हैं और हम मुठभेड़ खतरनाक त्रुटि:MySQL/SQLAlchemy
1213, 'Deadlock found when trying to get lock; try restarting transaction'.
हम इस मामले में सबसे तीन बार में लेन-देन को पुनः आरंभ करने की कोशिश करना चाहते हैं।
मैंने एक सजावट लिखना शुरू कर दिया है जो ऐसा करता है लेकिन मुझे नहीं पता कि विफल होने से पहले सत्र स्थिति को कैसे सहेजना है और उसके बाद उसी लेनदेन को फिर से प्रयास करना है? (SQLAlchemy एक रोलबैक की आवश्यकता के रूप में जब भी कोई अपवाद उठाया है)
मेरा काम अब तक,
def retry_on_deadlock_decorator(func):
lock_messages_error = ['Deadlock found', 'Lock wait timeout exceeded']
@wraps(func)
def wrapper(*args, **kwargs):
attempt_count = 0
while attempt_count < settings.MAXIMUM_RETRY_ON_DEADLOCK:
try:
return func(*args, **kwargs)
except OperationalError as e:
if any(msg in e.message for msg in lock_messages_error) \
and attempt_count <= settings.MAXIMUM_RETRY_ON_DEADLOCK:
logger.error('Deadlock detected. Trying sql transaction once more. Attempts count: %s'
% (attempt_count + 1))
else:
raise
attempt_count += 1
return wrapper
क्या मैंने आपकी मदद की? या आपको एक और समाधान मिला। कृपया कोई परिणाम साझा करें। –