
正文
Python线程包装器
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
import threading
import subprocessimport timedef 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 innerif __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"






