วิธีที่ถูกต้องในการใช้ HTTPAdapter กับการเขียนโปรแกรม Async และการเรียกใช้เมธอดคืออะไร คำขอทั้งหมดนี้จัดทำขึ้นในโดเมนเดียวกัน
ฉันกำลังเขียนโปรแกรมแบบอะซิงก์ใน Celery โดยใช้ eventlet และทดสอบโหลดบนไซต์ใดไซต์หนึ่งของฉัน ฉันมีวิธีการที่ฉันเรียกใช้ซึ่งทำการร้องขอไปยัง url
def get_session(url): # gets session ส่งคืนส่วนหัวของซอร์ส, proxies = header_proxy() # ตั้งค่าตัวแปรที่จำเป็นทั้งหมดของเราเป็น None เพื่อว่าในกรณีที่เกิดข้อผิดพลาด # เราจะมั่นใจได้ว่าเราจะไม่ทำลายการตอบสนอง = none status_code = none out_data = ไม่มีเนื้อหา = ไม่มี
try:
# we are going to use request-html to be able to parse the
# data upon the initial request
with HTMLSession() as session:
# you can swap out the original request session here
# session = requests.session()
# passing the parameters to the session
session.mount('https://', HTTPAdapter(max_retries=0, pool_connections=250, pool_maxsize=500))
response = session.get(url, headers=headers, proxies=proxies)
status_code = response.status_code
try:
# we are checking to see if we are getting a 403 error on all requests. If so,
# we update the status code
code = response.html.xpath('''//*[@id="accessDenied"]/p[1]/b/text()''')
if code:
status_code = str(code[0][:-1])
else:
pass
except Exception as error:
pass
# print(error)
# assign the content to content
content = response.content
except Exception as error:
print(error)
pass
หากฉันละพารามิเตอร์ pool_connections
และ pool_maxsize
และเรียกใช้โค้ด ฉันได้รับข้อผิดพลาดที่ระบุว่าฉันมีการเชื่อมต่อที่เปิดไม่เพียงพอ อย่างไรก็ตาม ฉันไม่ต้องการเปิดการเชื่อมต่อจำนวนมากโดยไม่จำเป็นหากฉันไม่ต้องการ
Celery worker -l info -n apple --concurrency=100 --pool=eventlet
- person CENTURION   schedule 19.03.2019