Как работать с задачами.цикл и sqlite3 в discord.py

#python #sqlite #loops #discord.py

#питон #sqlite #петли #discord.py

Вопрос:

Когда я обрабатываю некоторые данные в винтиках и в этой работе. Цикл завершается неудачно, так как данные не синхронизированы и записывается, что база данных заблокирована. Я понимаю проблему, которая мешает работать с ботом в будущем, но при большом потоке людей все равно всплывает ошибка

 @tasks.loop(seconds = 1) async def secondLoop():  games = cursor.execute(f"SELECT players, joinedTimePlayers, channelId, id FROM games WHERE onPick = 0").fetchall()  guild = bot.guilds[0]   for game in games:  playersTime = game[1].split()  players = game[0].split()   if len(playersTime) gt; 0:  for playerTimeIndex in range(len(playersTime)):  try:  if int(playersTime[playerTimeIndex]) gt; 1:  playersTime[playerTimeIndex] = str(int(playersTime[playerTimeIndex]) - 1)  cursor.execute(f"UPDATE games SET joinedTimePlayers = '{nl.join(playersTime)}' WHERE id = {game[3]}")  connection.commit()   elif int(playersTime[playerTimeIndex]) == 1:  channel = bot.get_channel(game[2])  embedToChannel = discord.Embed(description = f"Пользователь lt;@!{players[playerTimeIndex]}gt; автоматически вышел из лобби, по причине бездействия", colour = discord.Color.red())  await channel.send(embed = embedToChannel)   playersTime[playerTimeIndex] = 0  players.remove(players[playerTimeIndex])  playersTime.remove(playersTime[playerTimeIndex])   cursor.execute(f"UPDATE games SET joinedTimePlayers = '{nl.join(playersTime)}', players = '{nl.join(players)}' WHERE id = {game[3]}")  connection.commit()  except Exception as e:  pass   

Комментарии:

1. Устранены, добавлены новые методы, которые используют with…as строительство после любой операции (обновление, чтение и т.д.)