Python学习————进程

方式一:

from multiprocessing import Process
import time

def task(x):
    print('%s is running' % x)
    time.sleep(5)
    print('%s is done' % x)


if __name__ == '__main__':
    p = Process(target=task, args=('子进程',))
    p.start()

print('主')

方式二:

from multiprocessing import Process
import time


class MyProcess(Process):
    def __init__(self,name):
        super().__init__()
        self.name = name

    def run(self):
        print('%s is running'%self.name)
        time.sleep(5)
        print('%s is over'%self.name)


if __name__ == '__main__':
    p = MyProcess('json')
    p.start()
    print('主')
posted @ 2020-04-22 21:27  Dimple_Y  阅读(112)  评论(0编辑  收藏  举报