【发布时间】:2017-01-10 05:28:39
【问题描述】:
我有这个脚本:
import threading, socket
for x in range(800)
send().start()
class send(threading.Thread):
def run(self):
while True:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("www.google.it", 80))
s.send ("test")
print ("Request sent!")
except:
pass
在“请求已发送!”的地方我想打印类似:"Request sent! %s" % (当前发送请求的线程数)
最快的方法是什么?
--已解决--
import threading, socket
for x in range(800)
send(x+1).start()
class send(threading.Thread):
def __init__(self, counter):
threading.Thread.__init__(self)
self.counter = counter
def run(self):
while True:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("www.google.it", 80))
s.send ("test")
print ("Request sent! @", self.counter)
except:
pass
【问题讨论】:
标签: python multithreading sockets python-3.x