Not sure how relevant this is, but I saw one small issue in the original script (possibly elsewhere):
In the comparison with top, grep is used to filter out results, but "hardcoded" to mysql, which doesn't seem to be generic... i.e. proc = subprocess.Popen("top -p %s -b -n 1 | grep -w mysql | awk '{print $9}'" % pid, shell=True, stdout=subprocess.PIPE)
proc = subprocess.Popen("top -p %s -b -n 1 | grep -w **mysql** | awk '{print $9}'" % pid, shell=True, stdout=subprocess.PIPE)
I'd suggest replacing "mysql" with the process name that is linked to the PID in question.