I managed to solve the problem. I used the “gameStart” event and called a shell script in parallel (If the script was not run in parallel, retroarch would only start after the shell script was fully executed).
/userdata/system/scripts/first_script.sh
#!/bin/bash
case $1 in
gameStart)
/userdata/system/setpal-m.sh &
;;
esac
And I delayed the execution of the python script.
/userdata/system/setpal-m.sh
#!/bin/bash
sleep 1
python3 /userdata/system/tweakvec.py --preset PAL-M
Thanks @Atari for the idea.