t5 commited on
Commit
8f56e4e
·
1 Parent(s): ea6f606
Files changed (1) hide show
  1. th.py +4 -3
th.py CHANGED
@@ -81,7 +81,8 @@ def pRun(Cb,jobs,nm,ars):
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)}
@@ -89,7 +90,7 @@ def thpoo(cb,urls,th=42,ve=()):
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
 
@@ -125,7 +126,7 @@ def main():#incremental search
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__':
 
81
  print(future.result()) # digest()の戻り値が表示される。
82
  # (上でas_completedをすべてイテレートしているので、実際にはこの時点で完了していないタスクは無いはず。)
83
  executor.shutdown()
84
+ #thpool
85
+ def pool(cb,urls,th=23,ve=()):
86
  li2=[None]*len(urls)
87
  with ThreadPoolExecutor(max_workers=th) as executor:
88
  future_to_url = {executor.submit(cb, url,*ve): x for x,url in enumerate(urls)}
 
90
  x = future_to_url[future]
91
  li2[x]=future.result()
92
  return li2
93
+ ##print(thpe(lambda ab,cd:ab+"23",["A","B"],23,["CD"]))
94
 
95
 
96
 
 
126
  for p in ps:
127
  p[0].start()
128
  time.sleep(0.5)
129
+ ## print pare.recv() # prints "[23, None, 'hello']"
130
  ## for p in ps: jw(p,)
131
 
132
  if __name__ == '__main__':