HTTP请求+线程是否有上限? 我正在编写一个程序,我将HTTP连接和请求放入线程中。 http请求到不同的服务器,但是线程会有异常,它无法启动线程。 显示我测试的异常的线程数约为670~680。 我确信问题出在HTTP请求上,因为当我删除请求时,我可以尽可能多地启动线程。
Class A():
for i in self.candidates:
example = SearchingThread()
self.devices.append(example)
for device in self.devices:
device.get_running()
class SearchingThread(object):
def __init__(self, interval=1):
self.interval = interval
self.thread = threading.Thread(target=self.run)
self.thread.daemon = True # Daemonize thread
self.sslconnect = http.client.HTTPSConnection
self.connect = http.client.HTTPConnection
self.context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
self.context.check_hostname = False
self.context.verify_mode = ssl.CERT_NONE
def get_running(self):
self.thread.start()
def run(self):
try:
self.sslconnect = http.client.HTTPSConnection(self.host, context=self.context, timeout=timeout)
self.sslconnect.request("GET", url, header)
resp = self.sslconnect.getresponse()