Python 多任务--9

多进程

import multiprocessing
import time
def sing():
    for i in range(0,200):
        print('sing.....')
        time.sleep(0.2)
def dance():
    for i in range(0,200):
        print('dance.....')
        time.sleep(0.2)

one = multiprocessing.process(target=sing)
two = multiprocessing.process(target=dance)

one.start()
two.start()

多线程

import threading
import time

def sing():
    for i in range(0,200):
        print('sing.....')
        time.sleep(0.2)
def dance():
    for i in range(0,200):
        print('dance.....')
        time.sleep(0.2)
        
one = threading.Thread(sing)
two = threading.Thread(dance)

one.start()
two.start()

你可能感兴趣的:(python)