python basic learning-day38 == homework exercises (creation process)

1. Two ways to achieve concurrency

# The first 
from multiprocessing Import Process
 Import Time


class MyProcess(Process):
    def run(self):
        print(f'{name} is running')
        time.sleep(3)
        print('over.....')


if __name__ == '__main__':
    p = MyProcess ()
    p.start()
    print ( ' main thread ' )

# Second 
from multiprocessing Import Process
 Import Time


def text(name):
    print(f'{name} is running')
    time.sleep(2)
    print('over....')


if __name__ == '__main__':
    p = Process(target=text,args = ('hz',))
    p.start()
    print ( ' main thread ' )

Guess you like

Origin www.cnblogs.com/dingbei/p/12755350.html