From 2dafdffce5fe02d5b3f0e67401f9bbaba31972e8 Mon Sep 17 00:00:00 2001 From: Herman Schistad Date: Fri, 18 Nov 2016 05:38:32 +0000 Subject: [PATCH] Allow multiple requests in parallel in Python client (#4187) * Allow multiple requests in parallel in Python client If you tried to do two parallel calls to the same API object in the Python client you would get an error from urllib3 connection pool: Connection pool is full, discarding connection: *** Because the default maxsize=1: https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L162 By defaulting to a higher maxsize we mitigate for the common use case where a user is running a couple of requests in parallel. Ideally, in the future, this should be a configuration paramater together with the pool size. * Add sample code after changing maxsize --- .../swagger-codegen/src/main/resources/python/rest.mustache | 4 +++- samples/client/petstore/python/petstore_api/rest.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index 8ddd17c473c..910d3001edf 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -49,10 +49,11 @@ class RESTResponse(io.IOBase): class RESTClientObject(object): - def __init__(self, pools_size=4): + def __init__(self, pools_size=4, maxsize=4): # urllib3.PoolManager will pass all kw parameters to connectionpool # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 + # maxsize is the number of requests to host that are allowed in parallel # ca_certs vs cert_file vs key_file # http://stackoverflow.com/a/23957365/2985775 @@ -78,6 +79,7 @@ class RESTClientObject(object): # https pool manager self.pool_manager = urllib3.PoolManager( num_pools=pools_size, + maxsize=maxsize, cert_reqs=cert_reqs, ca_certs=ca_certs, cert_file=cert_file, diff --git a/samples/client/petstore/python/petstore_api/rest.py b/samples/client/petstore/python/petstore_api/rest.py index a85e8c5bc74..5fda97044b3 100644 --- a/samples/client/petstore/python/petstore_api/rest.py +++ b/samples/client/petstore/python/petstore_api/rest.py @@ -58,10 +58,11 @@ class RESTResponse(io.IOBase): class RESTClientObject(object): - def __init__(self, pools_size=4): + def __init__(self, pools_size=4, maxsize=4): # urllib3.PoolManager will pass all kw parameters to connectionpool # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 + # maxsize is the number of requests to host that are allowed in parallel # ca_certs vs cert_file vs key_file # http://stackoverflow.com/a/23957365/2985775 @@ -87,6 +88,7 @@ class RESTClientObject(object): # https pool manager self.pool_manager = urllib3.PoolManager( num_pools=pools_size, + maxsize=maxsize, cert_reqs=cert_reqs, ca_certs=ca_certs, cert_file=cert_file,