线程共享全局状态,进程完全独立。线程局限在一个处理器,线程可以发挥多个处理器的资源.
没有找到processing模块只找到multiprocessing
#!/usr/bin/env python
from multiprocessing import Process,Queue
import time
q=Queue()

def f(q):
        x=q.get()
        print "Process number %s,sleeps for %s second" % (x,x)
        time.sleep(x)
        print "Process number %s finished" % x

for i in range(10):
        q.put(i)
        i=Process(target=f,args=[q])
        i.start()

print "main process joins on queue"
i.join()
print "Main Program finished"

多进程ping扫描
#!/usr/bin/env python
import subprocess
import time
import sys
from multiprocessing import Process,Queue
#multiprocessing 本身带有的Queue
num_Process=50
queue=Queue()

ips=['172.18.10.101','172.18.10.102','172.18.10.103','172.18.10.104','172.18.10.105']

def pinger(i,q):
        while True:
                if q.empty(): #增加:Process增加了查看列队是否为空
                        sys.exit()
                ip=q.get() #一样:取得队列内容threading和multiprocessing.Process一样,获取put过来的ip
                print "Process Numer: %s" % i
                ret=subprocess.call("ping -c 1 %s" % ip,shell=True,stdout=open('/dev/null','w'),stderr=subprocess.STDOUT)
                if ret==0:
                        print "Process Numer %s ping:%s is alive" % (i,ip)
                else:
                        print "Process Numer: %s did not find a response for %s" % (i,ip)
                #减少:没有threading的queue.task_done()
for ip in ips:
        queue.put(ip)  #一样:放入队列内容threading.Thread和multiprocessing.Process一样
#顺序很重要,需要先put ip
for i in range(num_Process):
        worker=Process(target=pinger,args=[i,queue]) #减少:没有threading.Thread的worker.setDaemon(True)
        worker.start()

print "Main joins on queue"
worker.join() #变化:由threading.Thread队列queue的join方法变成了multiprocessing.Process实例的join方法
print "Done"


multiprocessing.Process和threading.Thread比较
multiprocessing.Process没有的
queue.task_done() 
worker.setDaemon(True)   
两者都有的
queue.put(ip)
queue.get()
有方法但变化了的
queue.join() 变成了 worker.join()#队列的连接变成进行实例的连接
multiprocessing.Process增加了的(threading.Thread没有的)
queue.empty():