python 多进程,多线程简单的
# -*- coding:utf-8 -*-from time import ctime,sleepimport threading #线程import multiprocessing #多进程def talk(c,loop): for i in range(loop): print(" %s talk hello 51 zxw! %s" %(c,ctime())) sleep(3) def write(c,loop): for i in range(loop): print(" %s wite hello 51 zxw! %s" %(c,ctime())) sleep(5) threads = []# t1 = threading.Thread(target=talk,args=("t1",2)) #多线程用这个t1 = multiprocessing.Process(target=talk,args=("t1",2)) #多进程用这个 threads.append(t1)# t2 = threading.Thread(target=write,args=("t1",2))t2 = multiprocessing.Process(target=write,args=("t1",2)) threads.append(t2)if __name__ == "__main__": for t in threads: t.start() for t in threads: t.join() print("all the end %s" %ctime())