Make a script run in backgroud

i have created a custom script that runs on “after_insert” on LMS Quiz Submission.
The script extracts the question and answer of quiz and sends it to a llm for evaluation. So it takes quite a bit time to get response and i have to sit in this page

i want the script to run in background and want the user to go to this page after pressing submit

i run the script from hooks.py

actually the processing does happen in the background but i want to make it so that when i press submit i can go to the quiz summary page