import threading import subprocess import os import sys class subprocess_thread(threading.Thread): def __init__(self, filename): threading.Thread.__init__(self) self.filename = filename def run(self): FNULL = open(os.devnull, 'w') cmd = subprocess.Popen(['python', self.filename, '&'], stdout=FNULL, stderr=FNULL, shell=True) cmd.communicate() cmd.kill() script_thread = subprocess_thread('test.py') script_thread.start()