import threading
import subprocess
import time
def need_thread(func, *args, **kwargs):
def fun():
print "sub:" + str(threading.current_thread().ident)
time.sleep(1)
sub = func(*args, **kwargs)
print sub.stdout.read()
print "sub down"
def inner():
t = threading.Thread(target=fun)
t.start()
return inner
if __name__ == '__main__':
need_thread(subprocess.Popen, "ls -al", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)()
print "main:" + str(threading.current_thread().ident)
print "main done"