import sys
import socket
import time
import threading
start_time = time.time()
class mythread(threading.Thread):
def __init__(self,threadname):
threading.Thread.__init__(self)
self._run_num = num
def run(self):
global count, mutex
threadname = threading.currentThread().getName()
for i in range(int(self._run_num)):
#get lock
mutex.acquire()
count = count + 1
#release lock
mutex.release()
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('localhost',8001))
mysock.send('1')
rdata = mysock.recv(50)
print i, 'received:', rdata
mysock.close()
if __name__ == "__main__":
global count, mutex
threads = []
num = 5
count = 1
#create lock
mutex = threading.Lock()
for x in range(0, num):
threads.append(mythread(5))
for t in threads:
t.start()
for t in threads:
t.join()
print "Elapsed Time: %s" % (time.time() - start_time)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PythonSocket.rar (3个子文件)
Client.py 410B
多线程.py 1KB
Server.py 594B
共 3 条
- 1
zmz911
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页