नोट: इस समाधान केवल यदि आप कनेक्शन पूल का निर्माण कार्य (@ Jahaja के जवाब में वर्णित है) नियंत्रित नहीं कर सकते का प्रयोग करें।
समस्या यह है कि urllib3
मांग पर पूल बनाता है। यह पैरामीटर के बिना urllib3.connectionpool.HTTPConnectionPool
कक्षा के निर्माता को कॉल करता है। कक्षाएं urllib3 .poolmanager.pool_classes_by_scheme
में पंजीकृत हैं।
def patch_http_connection_pool(**constructor_kwargs):
"""
This allows to override the default parameters of the
HTTPConnectionPool constructor.
For example, to increase the poolsize to fix problems
with "HttpConnectionPool is full, discarding connection"
call this function with maxsize=16 (or whatever size
you want to give to the connection pool)
"""
from urllib3 import connectionpool, poolmanager
class MyHTTPConnectionPool(connectionpool.HTTPConnectionPool):
def __init__(self, *args,**kwargs):
kwargs.update(constructor_kwargs)
super(MyHTTPConnectionPool, self).__init__(*args,**kwargs)
poolmanager.pool_classes_by_scheme['http'] = MyHTTPConnectionPool
तो फिर तुम नए डिफ़ॉल्ट पैरामीटर सेट करने के लिए कॉल कर सकते हैं: चाल अपनी कक्षाओं भिन्न डिफ़ॉल्ट मापदण्डों की कक्षाओं को बदलने के लिए है। सुनिश्चित करें कि किसी भी कनेक्शन से पहले इसे कहा जाता है।
patch_http_connection_pool(maxsize=16)
आप https कनेक्शन का उपयोग करते हैं तो आप एक समान कार्य बना सकते हैं:
def patch_https_connection_pool(**constructor_kwargs):
"""
This allows to override the default parameters of the
HTTPConnectionPool constructor.
For example, to increase the poolsize to fix problems
with "HttpSConnectionPool is full, discarding connection"
call this function with maxsize=16 (or whatever size
you want to give to the connection pool)
"""
from urllib3 import connectionpool, poolmanager
class MyHTTPSConnectionPool(connectionpool.HTTPSConnectionPool):
def __init__(self, *args,**kwargs):
kwargs.update(constructor_kwargs)
super(MyHTTPSConnectionPool, self).__init__(*args,**kwargs)
poolmanager.pool_classes_by_scheme['https'] = MyHTTPSConnectionPool
स्रोत
2014-03-07 15:06:21
यह मेरे लिए काम करता है। इसे सही उत्तर के रूप में चिह्नित किया जाना चाहिए। – reish