Python 多进程

import threading
from time import sleep
from msalt_proxy.client import Client
def f(t):
  print t
  cli=Client(t,'*',role='server')
  cli.sys.ping()
from multiprocessing import Process
if __name__ == '__main__':
     p = Process(target=f, args=('ljx2',))
     p.start()
     p.join()
     p1 = Process(target=f, args=('ljx1,))
     p1.start()
     p1.join()

  

def s_chksalt(request):
    proxy_path = settings.proxy_path
    confs = os.listdir(proxy_path)
    def func(q, conf):
        items = conf.split('.')
        tmp = items[0] + '.' + items[1]
        q.put(tmp )
    ret = []
    q = Queue()
    ps=[]

    for conf in confs:
        p = Process(target=lambda: func(q,conf))
        p.start()
        ps.append(p)
    for p in ps:
        p.join()
    for i in range(q.qsize()):
        ret += q.get()
    return fResponse({'data': ret,'retcode':1})

  

posted @ 2014-06-18 16:52  Xjng  阅读(720)  评论(0编辑  收藏  举报