I
I
Izzy Kotov2021-07-14 07:44:12
Python
Izzy Kotov, 2021-07-14 07:44:12

How to fix The object was created in thread id 11400 and this is thread id 4040 error?

from RXConfigBase import *
from RXSQLConfig import *
#from RXKeyboardConfig import *

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)
logger = logging.getLogger(__name__)

#Начало, логиниться и регистрация
@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.from_user.id,  "Добро пожаловать!\n" f"‍♂️>> {message.chat.first_name}|{message.chat.last_name} <<‍♀️\n\n" "Входа в систему /log\n" "Регистрация /reg")

#регистрация
@bot.message_handler(content_types=['text'])
def reg(message):
    if message.text == '/reg':
        global user_id
        global name
        bot.send_message(message.from_user.id, 'Регистрация аккаунта.\nУкажите имя')
        user_id = message.from_user.id
        bot.register_next_step_handler(message, name)

    elif message.text == '/log':
        cursor.execute("SELECT name, surname, patronymic FROM users ORDER BY name, surname, patronymic")
        name = cursor.fetchall()
        surname = cursor.fetchall()
        patronymic = cursor.fetchall()
        bot.send_message(message.from_user.id, 'Профиль\n'
                                                f'{name}\n'
                                                f'{surname}\n'
                                                f'{patronymic}'                        
                        )



#Собираем данные для регистрации и БД
def name(message): #получаем имя
    if message.text:
        bot.send_message(message.from_user.id, 'Укажите фамилию')
        global name
        name = message.text
        bot.register_next_step_handler(message, surname)

def surname(message): #получаем фамилии
    if message.text:
        bot.send_message(message.from_user.id, 'Укажите отчество')
        global surname
        surname = message.text
        bot.register_next_step_handler(message, patronymic)

def patronymic(message): #получаем отчества
    if message.text:
        bot.send_message(message.from_user.id, 'Регистрация окончено! Напиши /log')
        global patronymic
        patronymic = message.text
        conn = sqlite3.connect("database/RXDataBase.db")
        cursor = conn.cursor()
        cursor.execute("INSERT INTO Profile (user_id, name, surname, patronymic) VALUES (?, ?, ?, ?)", (user_id, name, surname, patronymic))
        conn.commit()



if __name__ == '__main__':
    bot.polling(none_stop=True, interval=0)

All error
line 27, in reg
cursor.execute("SELECT name, surname, patronymic FROM users ORDER BY name, surname, patronymic")
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 11400 and this is thread id 4040.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-07-14
@HellcatT150

Where does the cursor come from in the reg function? Judging by the text of the error, it is created in a different place and in a different thread, but this is not possible. Also, it looks like you don't understand the DB API. Why are you calling fetchall three times?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question