Python线程包装器

Posted 413Xiaol

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python线程包装器相关的知识,希望对你有一定的参考价值。

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线程包装器的主要内容,如果未能解决你的问题,请参考以下文章