潇洒郎: python multiprocess,subproess 多进程执行、控制

多进程多线程执行:

# coding=utf-8
# Author: xuxiaosa
# Created_Date: 2022/5/14
# Created_Time: 20:1

import time
import threading
import multiprocessing

class MyThread:
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
        self.thread = None

    def start(self):
        self.thread = threading.Thread(*self.args, **self.kwargs)
        self.thread.start()

    def join(self):
        self.thread.join()


def threading_func(i):
    print(f'Starting Function {i}')
    time.sleep(1)
    print(f'Ending Function {i}')


def process_func(threads):
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()

# Required for Windows:
if __name__ == '__main__':
    thread_list = [MyThread(target=threading_func, args=(i,)) for i in range(1, 9)]
    processes = [multiprocessing.Process(target=process_func, args=([threa

版权声明:本文为qq_32711799原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。