Last active
February 29, 2020 14:31
-
-
Save mrchoke/d94b247fd978696f17aa5f5b2d5c2331 to your computer and use it in GitHub Desktop.
ตัวอย่างการแตก Thread มารับงานทำเสร็จก็เสร็จกันไปไม่ต้องรอ ง่ายกว่าใช้ Threading แบบปกติ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures | |
from datetime import datetime | |
import time | |
import random | |
def process(i, data): | |
t = random.randrange(5) | |
time.sleep(t) | |
print("Process index:", i, ' Sleep:', t, ' Current:', datetime.now()) | |
if __name__ == "__main__": | |
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor: | |
for i in range(10): | |
executor.submit(process, i, datetime.now()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment