-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
29 lines (25 loc) · 828 Bytes
/
client.py
File metadata and controls
29 lines (25 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding:utf-8 -*-
import time
from Util.socketutils import Client
import threading
from concurrent.futures import ThreadPoolExecutor, as_completed
if __name__ == '__main__':
client = Client(host='127.0.0.1', port=3333)
l1 = []
for i in range(100):
l1.append(str(i))
task_list = []
threadpool = ThreadPoolExecutor(5)
single = False
if single:
s = client.create_socket(bind=False)
for msg in l1:
# 单socket通信
if single:
task_list.append(threadpool.submit(client.send_message_ex, s, msg, False))
else:
task_list.append(threadpool.submit(client.send_message_ex, None, msg, True))
# 等待线程池中所有任务完成
for result in as_completed(task_list):
res = result.result()
print(len(task_list))