Python線程包裝器
阿新 • • 發佈:2018-01-14
rgs target true std pro roc sta __main__ art
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"
Python線程包裝器