首页 > 编程语言 > 详细

Python线程包装器

时间:2018-01-14 21:12:12      阅读:266      评论:0      收藏:0      [点我收藏+]
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线程包装器

原文:https://www.cnblogs.com/413xiaol/p/8284151.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!