123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #!/usr/bin/env python
- # -*- coding=utf-8 -*-
- import sys
- sys.path.append(r"D:\ProgramData\Anaconda2\Lib")
- sys.path.append(r"D:\vi\vi_server")
- #import ibm_ai
- from multiprocessing import Process,Lock
- import time
- from multiprocessing import Pool,Manager
- import json
- import os
- class Add:
- _total=0
- def __init__(self,a,b):
- self._total=a+b
- print("total:",self._total)
- def add(self,c):
- self._total+=c
- print("total:",self._total)
- def sub(self,c):
- self._total-=c
- print("total:",self._total)
- def get_total(self):
- return self._total
- # add=Add(1,2)
- # def add_c(c):
- # global add
- # add.add(c)
- # return add.get_total()
- # def sub_c(c):
- # global add
- # add.sub(c)
- # return add.get_total()
- # def get_cwd():
- # # json1={'a':'1'}
- # # json2={'b':'2'}
- # # json=ibm_ai.merge_json(json1,json2)
- # return os.getcwd()
- #print("hello world total:",add_c(1))
- def foo(n,queue):
- # print("ok")
- # if lock is None:
- # print("lock is None")
- time.sleep(6-n)
- #lock.acquire()
- #print('In process:', n, os.getpid())
- #lock.release()
- queue.put("AI_result:"+str(n))
- return n
- def bar(*args):
- results.append(args[0])
- print('>>done: ', args, os.getpid())
- def l(num,lock,p):
- lock.acquire()
- #stime.sleep(2)
- print ("Hello num:%s" ,num)
- lock.release()
- results=[]
- if __name__=='__main__':
- json_str="{\"shape_type\":\"line\",\"shape_data\":[[12,1],[12,2]],\"value\":\"\",\"action\":\"add\"}"
- # j={"shape_data":[(1,2),(3,4)]}
- # str_j=json.dumps(j)
- #print("str_j:",str_j)
- # json_obj=json.loads(json_str)
- # print(json_obj["shape_data"][0][0])
- # lock=Lock()
- # pool = Pool(processes=3)
- # json_obj={"j":lock}
- # queue = Manager().Queue()
- # concurrency=6
- # for num in range(concurrency):
- # #Process(target=foo,args=({"i":num}, )).start()
- # pool.apply_async(func=foo, args=(num,queue))
- # print("async:",num)
-
- # num=0
- # while num<concurrency:
- # res= queue.get()
- # print("res:",res)
- # num+=1
- # time.sleep(0.01)
- # pool.close()
- # pool.join()
- # if __name__ == "__main__":
- # pool = Pool(processes=3)
- # lock=Lock()
- # print('main process:', os.getpid())
- # for i in range(6):
- # # pool.apply(func=foo, args=(i, ))
- # pool.apply_async(func=foo, args=({"i":i},), callback=bar)
- # print('end')
- # pool.close()
- # pool.join()
- # p = multiprocessing.Process(target=process_run, args=(i,))
- # p.start()
|