python进程与线程混合使用例子

来源:互联网 发布:开源搜索引擎源码 编辑:程序博客网 时间:2024/06/07 06:12
from gevent import monkey; monkey.patch_all()
import gevent
import multiprocessing
import threading
import time


def thread_handle():
    print ("\033[1;33;42m now,begin handle thread task.......\033[0m")
    time.sleep(2)
    print("\033[1;31;42m now,end handle thread task.......\033[0m")


def process_handle():
    print ("now,begin handle process task.........")
    t_list = []
    for i in range(5):
        t = threading.Thread(target=thread_handle,)
        t.start()
        t_list.append(t)
    for i in t_list:
        i.join()




if __name__ == '__main__':
    p_list = []
    for i in range(10):
        p = multiprocessing.Process(target=process_handle,)
        p.start()
        p_list.append(p)
    for i in p_list:
        i.join()
    print ("now,every process task handle complete.........")