i want inquire regarding reusing same connection while having loop sending same post request. assume have code:
import requests import time r = requests.session() url = "http://somenumbers.php" while true: x = r.post(url) time.sleep(10) now according documentation of requests library
excellent news — urllib3, keep-alive 100% automatic within session! requests make within session automatically reuse appropriate connection! note connections released pool reuse once body data has been read; sure either set stream false or read content property of response object
does work code above? trying prevent sending same request in case server freezes or read timeout occurs. in issue sending post requests using library requests go on whole problem, , 1 of suggestions reuse connection, but
isn't sending same request on same connection mean multiple entries, or going fix issue since pull when 1 entry sent documentation states?
assuming latter true, won't affect performance , cause long delays since request trapped inside connection?!
r.post blocking call. function return once request has been sent , response received. long access x.content before loop terminates, next loop re-use underlying tcp connection.
isn't sending same request on same connection mean multiple entries, or going fix issue since pull when 1 entry sent documentation states?
requests doesn't cache response. not check if previous request having same parameters made. if need that, have build on own.
won't affect performance , cause long delays since request trapped inside connection
requests re-use available connection. if no free connection exists, new connection established. can use requests.packages.urllib3.poolmanager.poolmanager control number of connections in pool.
Comments
Post a Comment