#方法一
from concurrent.futures import ThreadPoolExecutor
import threading
import json
from queue import Queue
lst = [ json.dumps({str(i):str(i * 2)}) for i in range(100)]
q = Queue(20)
def readS():
for s in lst:
q.put(s)
def getS():
while True:
if q.empty():
break
s = q.get()
print(json.loads(s))
for k in range(1):
k = threading.Thread(target=readS,)
k.start()
for i in range(5):
t = threading.Thread(target=getS,)
t.start()
#方法二
executor = ThreadPoolExecutor(max_workers=5)
res = executor.map(json.loads, lst)
for i in res:
print(i)
方法一是当时潜意识的写法,之后讨论过程中,想到的方法二