Python线程池

47 阅读1分钟
import threading
from concurrent.futures import ThreadPoolExecutor


def app(data):
    print(threading.current_thread(), '+++++', data)
    return True


if __name__ == '__main__':
    data = [
        {
            "id": "order-41c78a5c50c24571a3b4895406527938",
            "from": "ST",
            "idx": 90441
        },
        {
            "id": "order-e68fe3995ccb4a29b5304810bbc5264e",
            "from": "ST",
            "idx": 90439
        }
    ]
    with ThreadPoolExecutor(max_workers=10) as executor:
        app1 = list(executor.map(app, data))
        print(app1)