The issue of executing terminal commands and keeping them active even when the terminal has closed is common.
Simple solution: Nohup command
{shell}nohup command options
if you wish to kill the background process, use the kill <PID> command.
Example
{shell}nohup python your_script.py
there are more advanced ways like temux or screens, but I haven't had a proper usecase for them.