Код: Выделить всё
if user['balance'] >= amount:
# Credit the target user's account
conn.execute('UPDATE users SET balance = balance + ? WHERE account_number = ?',
(amount, target_account_number))
conn.close() # Immediately close connection to force an early write
# Simulate a delay to allow race condition
import time
time.sleep(2) # Simulate delay
# Open a new connection for the debit operation
conn = get_db()
# Debit the sender's account
conn.execute('UPDATE users SET balance = balance - ? WHERE account_number = ?',
(amount, session['user']))
conn.close() # Close connection to apply the change immediately
flash(f'Success! Transferred ${amount} to account {target_account_number}.')
else:
flash('Insufficient funds.')
return redirect(url_for('dashboard'))
Подробнее здесь: https://stackoverflow.com/questions/790 ... -in-python
Мобильная версия