import subprocess import multiprocessing import urllib import sys import os import pymongo import signal import time client=pymongo.MongoClient("192.168.139.143",27017) db=client.domaindb collection=db.domain def getdomain(i): print("process id=%d,paren process id=%d,ppange=%d"%(os.getpid(),os.getppid(),i)) time.sleep(1) getdomain(i+1)
if __name__ == '__main__': try: pool=multiprocessing.Pool(6) pool.map(getdomain,range(8)) #pool.map_async(getdomain,range(9)).get(10) pool.close() except KeyboardInterrupt: print 'get ctrl+c whild pool' pool.terminate() #except TimeoutException: except Exception ,e: print 'thrwo exception %r'%(e) finally: print 'joining complete' #pool.join() print 'join compele' print 'the end'