I'm writing a sorting algorithm visualisation in python using pygame. I've come to an end, everything seems to work just fine, except the fact that the Pygame Window stops responding after a few seconds.
I've tried all solutions I could find, but none worked so far. If anyone could give me an insight into this code, I'd be grateful
import random
import time
import pygame
import color_constants as colors
import ctypes
from pygame.locals import *
def readData():
    listOfNumbers = []
    data = dict()
    print("Lowest Value: ")
    numLow = int(input())
    print("Highest Value: ")
    numHigh = int(input())
    print("Length of list: ")
    n = int(input())
    for i in range(0, n):
        listOfNumbers.append(random.randint(numLow, numHigh))
    data.update({'lst': listOfNumbers})
    data.update({'numLow': numLow})
    data.update({'numHigh': numHigh})
    data.update({'n': n})
    return data
def checkSorting(lst):
    ok = True
    for i in range(0, len(lst) - 1):
        if lst[i] > lst[i + 1]:
            ok = False
    if ok is True:
        print("Sorting Check, OK = True")
        return True
    else:
        print("Sorting Check, OK = False")
        return False
def drawRect(lst):
    for i in range(len(lst)):
        rect = Rect(i * RECT_W, 0, RECT_W, RECT_H * lst[i])
        rect.bottom = SCREEN_H
        pygame.draw.rect(screen, BLACK, rect)
        pygame.display.flip()
def bubblesort(lst):
    for i in range(0, len(lst) - 1):
        for j in range(i + 1, len(lst)):
            if lst[i] > lst[j]:
                aux = lst[i]
                lst[i] = lst[j]
                lst[j] = aux
                drawRect(lst)
    return lst
if __name__ == "__main__":
    # Setting up the color literals
    BLACK = colors.BLACK
    WHITE = colors.WHITE
    # Getting the user's screen size
    user32 = ctypes.windll.user32
    SCREENSIZE = user32.GetSystemMetrics(0)-100, user32.GetSystemMetrics(1)-100
    SCREEN_W = SCREENSIZE[0]
    SCREEN_H = SCREENSIZE[1]
    data = readData()
    # Setting and scaling the size of rectangle based on the number of elements (n)
    # and the highest number (numHigh)
    RECT_W = SCREEN_W // data['n']
    RECT_H = SCREEN_H / (data['numHigh'])
    pygame.init()
    screen = pygame.display.set_mode(SCREENSIZE)
    screen.fill(WHITE)
    running = True
    while running:
        pygame.event.pump()
        bubblesort(data['lst'])
    pygame.quit()