import subprocess subprocess.getoutput('date') # python3 getoutput方法
import multiprocessing import time import os def whoami(name): print("I'm %s, in process %s" % (name, os.getpid())) def loopy(name): whoami(name) start = 1 stop = 1000000 for num in range(start, stop): print(" Number %s of %s. Honk!" % (num, stop)) time.sleep(1) if __name__ == "__main__": whoami("main") p = multiprocessing.Process(target=loopy, args=("loopy",)) p.start() time.sleep(5) p.terminate() #输出 ''' I'm main, in process 1528 I'm loopy, in process 1529 Number 1 of 1000000. Honk! Number 2 of 1000000. Honk! Number 3 of 1000000. Honk! Number 4 of 1000000. Honk! Number 5 of 1000000. Honk!'''