码迷,mamicode.com
首页 > 编程语言 > 详细

Python线程包装器

时间:2018-01-14 21:22:26      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:rgs   pop   std   targe   sleep   线程   sub   *args   get   

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线程包装器

标签:rgs   pop   std   targe   sleep   线程   sub   *args   get   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!