Spaces:
Sleeping
Sleeping
t5 commited on
Commit ·
95caa65
1
Parent(s): a721014
apple
Browse files- neo server.py +2 -2
- th.py +139 -0
neo server.py
CHANGED
|
@@ -81,5 +81,5 @@ def handle_post():
|
|
| 81 |
@app.get("/")
|
| 82 |
def read_root():
|
| 83 |
return {"Hello": "World..1"}
|
| 84 |
-
|
| 85 |
-
|
|
|
|
| 81 |
@app.get("/")
|
| 82 |
def read_root():
|
| 83 |
return {"Hello": "World..1"}
|
| 84 |
+
if host!="face":
|
| 85 |
+
app.run()
|
th.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
from threading import Thread,Lock,Event,Condition
|
| 3 |
+
import multiprocessing as mlti
|
| 4 |
+
|
| 5 |
+
class orth:#(th.Thread):
|
| 6 |
+
lock=Lock()
|
| 7 |
+
orEv=Event()
|
| 8 |
+
def thpr(*a):
|
| 9 |
+
with orth.lock:
|
| 10 |
+
print(a,end="-")
|
| 11 |
+
def run(cb,args):
|
| 12 |
+
t=Thread(target=cb,args=args)
|
| 13 |
+
t.start()
|
| 14 |
+
return t
|
| 15 |
+
def runi(sl,cb,data,mod,vl):
|
| 16 |
+
liImz=[Thread(target=cb, args=(vl,x,data,[])) for x in range(mod)]
|
| 17 |
+
for j in liImz: j.start()
|
| 18 |
+
return liImz
|
| 19 |
+
def thrun(thFind,iList,nm,ars):
|
| 20 |
+
"thFind(ars,sepnm,iList,oList)"
|
| 21 |
+
#l=list.split(nm)
|
| 22 |
+
#(len(oList)*i)/nm
|
| 23 |
+
#separater_span_block_colon_range_窓関数_
|
| 24 |
+
sep=len(iList)/nm
|
| 25 |
+
sepnm=int(sep+1)#+0.5)
|
| 26 |
+
#sepnm=len(iList)//nm+1#floordivision
|
| 27 |
+
oList=[]#[[] for i in range(nm)]
|
| 28 |
+
liImz=[]
|
| 29 |
+
for i in range(nm):
|
| 30 |
+
#th
|
| 31 |
+
oList.append([])
|
| 32 |
+
if not(sepnm*(i+1)>=len(iList)):
|
| 33 |
+
rang=(sepnm*i,sepnm*(i+1))
|
| 34 |
+
imz=Thread(target=thFind,args=(ars,rang,iList,oList[i]))
|
| 35 |
+
liImz.append(imz)
|
| 36 |
+
else:
|
| 37 |
+
rang=(sepnm*i,len(iList))
|
| 38 |
+
imz=Thread(target=thFind,args=(ars,rang,iList,oList[i]))
|
| 39 |
+
liImz.append(imz)
|
| 40 |
+
break
|
| 41 |
+
for j in liImz: j.start()
|
| 42 |
+
for i,j in enumerate(liImz):
|
| 43 |
+
res=jw(j,)
|
| 44 |
+
#None print(res,i)
|
| 45 |
+
return oList
|
| 46 |
+
def threadAny(thFind,iList,ars):
|
| 47 |
+
"thFind(ars,sepnm,iList,oList)"
|
| 48 |
+
oList=[[] for i in range(len(iList))]
|
| 49 |
+
liImz=[]
|
| 50 |
+
for i,j in enumerate(iList):
|
| 51 |
+
def crProc(proc):
|
| 52 |
+
def f1(*a):
|
| 53 |
+
proc(*a)
|
| 54 |
+
orEv.set()
|
| 55 |
+
return f1
|
| 56 |
+
imz=Thread(target=crProc(thFind),args=(ars,j,oList[i]))
|
| 57 |
+
liImz.append(imz)
|
| 58 |
+
for j in liImz: j.start()
|
| 59 |
+
for i,j in enumerate(liImz):
|
| 60 |
+
orEv.clear()#block<>set() green light
|
| 61 |
+
n=orEv.wait(timeout=5)
|
| 62 |
+
#call set() elsewhere
|
| 63 |
+
if not n:return 0
|
| 64 |
+
rn1=[j for j in oList if j][0]
|
| 65 |
+
return rn1
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
import concurrent
|
| 72 |
+
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
|
| 73 |
+
def pRun(Cb,jobs,nm,ars):
|
| 74 |
+
job = jobs
|
| 75 |
+
executor = concurrent.futures.ProcessPoolExecutor(max_workers=nm)
|
| 76 |
+
futures = [executor.submit(Cb,t) for t in job]#start
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
# as_completed()は、与えられたfuturesの要素を完了順にたどるイテレータを返す。
|
| 80 |
+
for future in concurrent.futures.as_completed(futures):# block
|
| 81 |
+
print(future.result()) # digest()の戻り値が表示される。
|
| 82 |
+
# (上でas_completedをすべてイテレートしているので、実際にはこの時点で完了していないタスクは無いはず。)
|
| 83 |
+
executor.shutdown()
|
| 84 |
+
def thpoo(cb,urls,th=42,ve=()):
|
| 85 |
+
li2=[None]*len(urls)
|
| 86 |
+
with ThreadPoolExecutor(max_workers=th) as executor:
|
| 87 |
+
future_to_url = {executor.submit(cb, url,*ve): x for x,url in enumerate(urls)}
|
| 88 |
+
for future in concurrent.futures.as_completed(future_to_url):
|
| 89 |
+
x = future_to_url[future]
|
| 90 |
+
li2[x]=future.result()
|
| 91 |
+
return li2
|
| 92 |
+
##print(thpe(lambda ab,cd:ab+"42",["A","B"],42,["CD"]))
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def main():#incremental search
|
| 101 |
+
import time
|
| 102 |
+
def timeo(duration=0.2):
|
| 103 |
+
def fi(te="something"):
|
| 104 |
+
for j in te:
|
| 105 |
+
time.sleep(duration)
|
| 106 |
+
yield j
|
| 107 |
+
newflag=0
|
| 108 |
+
if(newflag):#cansel this thread
|
| 109 |
+
return 2
|
| 110 |
+
return 1
|
| 111 |
+
return fi
|
| 112 |
+
global pro,pr1;
|
| 113 |
+
def pro(conn,cb,ars,li):
|
| 114 |
+
for j in cb(ars):
|
| 115 |
+
conn.send(j)
|
| 116 |
+
ri=conn.recv()
|
| 117 |
+
print(ri)
|
| 118 |
+
pr1=timeo()
|
| 119 |
+
#
|
| 120 |
+
ps=[]
|
| 121 |
+
for j in "inc":
|
| 122 |
+
pare, child = mlti.Pipe()
|
| 123 |
+
ps.append(( mlti.Process(target=pro, args=(child,1234,(j*9),None)),pare,child))
|
| 124 |
+
#cant pickle local callback
|
| 125 |
+
for p in ps:
|
| 126 |
+
p[0].start()
|
| 127 |
+
time.sleep(0.5)
|
| 128 |
+
## print pare.recv() # prints "[42, None, 'hello']"
|
| 129 |
+
## for p in ps: jw(p,)
|
| 130 |
+
|
| 131 |
+
if __name__ == '__main__':
|
| 132 |
+
## main()
|
| 133 |
+
from multiprocessing import shared_memory
|
| 134 |
+
## m=mlti.shared_memory.SharedMemory("fil",True,1)
|
| 135 |
+
## m=mlti.shared_memory.SharedMemory("fil",False,1)
|
| 136 |
+
## print(m)
|
| 137 |
+
import mmap
|
| 138 |
+
m=mmap.mmap(-1,3,"fil")
|
| 139 |
+
print(m.tell(),m.read())
|