import os
import time
import subprocess
if __name__=="__main__":
    print("keep xunlei running");
    while 1:
        str = subprocess.check_output('tasklist')
        print str
        if str.find('ThunderPortable.exe')==-1:
            print("xunlei is crashed, restart");
            #os.spawnl(os.P_NOWAIT, r'C:\ThunderPortable\ThunderPortable.exe')
            subprocess.Popen(["ThunderPortable.exe"])
        else:
            print("xunlei is running!");
        time.sleep(30)