Two ways to open threads in python concurrent programming

The first:

from multiprocessing import Process
from threading import Thread
import time
class MyThread(Thread):
    def run(self):
        print('%s is running' %self.name)
        time.sleep(3)
if __name__ == '__main__':
    t = MyThread()
    t.start()
    print ( ' This is the main thread ' )

the second

from multiprocessing import Process
from threading import Thread
import time

def task(name):
    print('%s is running'%name)
    time.sleep(3)

if __name__ == '__main__':
    t = Thread(target=task,args=( ' egon ' ,))
     # t = Process(target=task,args=('egon',)) 
    t.start()
     print ( ' This is the main thread ' )

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324887504&siteId=291194637