Python. Библиотека treading + telethon. Окно с программой просто не отвечает

в одном потоке клиент телеги из локального .py файла, который парсит диалоги, добавляет их в sql таблицу и джесонами сообщения записывает, в другом потоке, который мейн, окошко, которое результаты его работы отображает, как клиент телеги, чтобы етот клиент постоянно обновлял результаты я их разобрал как бы на два потока, но ничего не работает и прога просто встает, окошко не реагирует на взаимодействие с ним.

class TelethonThread(Thread):
def __init__(self):
    Thread.__init__(self)

def run(self):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    print('telethon is running')
    with client:
        client.loop.run_until_complete(main())
    print('telethon cycle passed')

class MainThread(Thread):
def __init__(self):
    Thread.__init__(self)

def run(self):
    global running, scrolled
    print('pygame is running')
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()
                sys.exit()
            if event.type == pygame.KEYDOWN:
                print('keydowned')
                if printing:
                    if event.key == pygame.K_RETURN:
                        for line in input_lines:
                            if line.message != '':
                                msg = line.message
                                user = line.user
                                line.message = ''
                                break
                        with client:
                            client.loop.run_until_complete(send_message(user, msg))
                    if event.key == pygame.K_BACKSPACE:
                        for line in input_lines:
                            line.message = line.message[:-1]
                    else:
                        try:
                            u = ctypes.windll.LoadLibrary("user32.dll")
                            pf = getattr(u, "GetKeyboardLayout")
                            lang = hex(pf(0))
                            if lang == '0x4190419':
                                letter = self.from_english(chr(event.key))
                            else:
                                letter = chr(event.key)
                            for line in input_lines:
                                line.message += letter
                                print(line.message, line.text_rect, line.text, line.text_rect.width)
                        except Exception:
                            pass
            if event.type == pygame.MOUSEMOTION:
                print('mouse moved')
                for window in dialogue_task:
                    window.check_position(event.pos[0], event.pos[1])
                for window in dialogue_windows:
                    window.on_it(event.pos)
            if event.type == pygame.MOUSEBUTTONDOWN:
                print('mouse clicked')
                if event.button == 1:
                    for lines in input_lines:
                        lines.clicked(event.pos)
                if mouse_in_left:
                    if event.button == 4 and scrolled > 0:
                        for window in dialogue_task:
                            window.y += 400 // fps
                        scrolled -= 400 // fps
                    elif event.button == 5 and scrolled <= limit:
                        for window in dialogue_task:
                            window.y -= 400 // fps
                        scrolled += 400 // fps
                    elif event.button == 1:
                        for window in dialogue_task:
                            window.clicked()
                elif mouse_in_centre:
                    if event.button == 4:
                        for message in messages:
                            message.y += 400 // fps
                            message.y_end += 400 // fps
                    elif event.button == 5:
                        for message in messages:
                            message.y -= 400 // fps
                            message.y_end -= 400 // fps
        screen.fill((0, 25, 100))
        self.create_dialogs()
        all_sprites.update()
        clock.tick(fps)
        pygame.display.flip()

def create_dialogs(self):
    global limit
    dias_bd = sqlite3.connect('dialogues.sql')
    cur = dias_bd.cursor()
    dias = cur.execute("""SELECT user FROM dialogues""").fetchall()
    for dialogue in dias:
        limit += 53
        Dialog_Preview(dialogue[0])
    limit -= 600

def from_english(self, text):
    layout = dict(zip(map(ord, '''qwertyuiop[]asdfghjkl;'zxcvbnm,./`QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?~'''),
                      '''йцукенгшщзхъфывапролджэячсмитьбю.ёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,Ё'''))

    return text.translate(layout)

main_process = MainThread()
sub_process = TelethonThread()
main_process.start()
print('main process started')
sub_process.start()
print('sub_process started')

Ответы (0 шт):