From 5369c49b0229b5adf951e1332eb6fd8512e84871 Mon Sep 17 00:00:00 2001 From: deniszh Date: Sat, 1 Sep 2018 15:04:26 +0200 Subject: [PATCH 1/4] import setUpRandomResolver only for new Twisted --- lib/carbon/client.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/carbon/client.py b/lib/carbon/client.py index 67834cc71..e38976937 100644 --- a/lib/carbon/client.py +++ b/lib/carbon/client.py @@ -12,7 +12,6 @@ from carbon.util import pickle from carbon.util import PluginRegistrar from carbon.util import enableTcpKeepAlive -from carbon.resolver import setUpRandomResolver from carbon import instrumentation, log, pipeline, state try: @@ -29,6 +28,17 @@ except ImportError: log.debug("Couldn't import signal module") +try: + import twisted as _twisted + twisted_version = tuple(map(int, getattr(_twisted, '__version__', '0').split('.'))) + if twisted_version >= (17, 1): + from carbon.resolver import setUpRandomResolver + else: + setUpRandomResolver = None + del _twisted +except ImportError: + setUpRandomResolver = None + SEND_QUEUE_LOW_WATERMARK = settings.MAX_QUEUE_SIZE * settings.QUEUE_LOW_WATERMARK_PCT @@ -528,7 +538,11 @@ def __init__(self, router): # If we decide to open multiple TCP connection to a replica, we probably # want to try to also load-balance accross hosts. In this case we need # to make sure rfc3484 doesn't get in the way. - setUpRandomResolver(reactor) + if setUpRandomResolver: + setUpRandomResolver(reactor) + else: + print("You need Twisted >= 17.1.0 for using DESTINATION_POOL_REPLICAS.") + raise SystemExit(1) self.router = router self.client_factories = {} # { destination : CarbonClientFactory() } From b693724b5438ce3e9c1a33705c601ff57d91add6 Mon Sep 17 00:00:00 2001 From: deniszh Date: Sun, 2 Sep 2018 20:46:04 +0200 Subject: [PATCH 2/4] Keeping it simple --- lib/carbon/client.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/carbon/client.py b/lib/carbon/client.py index e38976937..1aa7d461f 100644 --- a/lib/carbon/client.py +++ b/lib/carbon/client.py @@ -29,13 +29,7 @@ log.debug("Couldn't import signal module") try: - import twisted as _twisted - twisted_version = tuple(map(int, getattr(_twisted, '__version__', '0').split('.'))) - if twisted_version >= (17, 1): from carbon.resolver import setUpRandomResolver - else: - setUpRandomResolver = None - del _twisted except ImportError: setUpRandomResolver = None @@ -541,7 +535,7 @@ def __init__(self, router): if setUpRandomResolver: setUpRandomResolver(reactor) else: - print("You need Twisted >= 17.1.0 for using DESTINATION_POOL_REPLICAS.") + print("Import error, you probably need Twisted >= 17.1.0 for using DESTINATION_POOL_REPLICAS.") raise SystemExit(1) self.router = router From ee4faf643b5c8c980902087235273d9bc7ca6109 Mon Sep 17 00:00:00 2001 From: deniszh Date: Sun, 2 Sep 2018 20:47:49 +0200 Subject: [PATCH 3/4] spacing --- lib/carbon/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carbon/client.py b/lib/carbon/client.py index 1aa7d461f..214cf3538 100644 --- a/lib/carbon/client.py +++ b/lib/carbon/client.py @@ -31,7 +31,7 @@ try: from carbon.resolver import setUpRandomResolver except ImportError: - setUpRandomResolver = None + setUpRandomResolver = None SEND_QUEUE_LOW_WATERMARK = settings.MAX_QUEUE_SIZE * settings.QUEUE_LOW_WATERMARK_PCT From 77eb5d1f710344d11d8f97a1cd4047a10d324ec3 Mon Sep 17 00:00:00 2001 From: deniszh Date: Mon, 3 Sep 2018 22:23:02 +0200 Subject: [PATCH 4/4] Taming E501 in linter --- lib/carbon/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carbon/client.py b/lib/carbon/client.py index 214cf3538..31aa75ae7 100644 --- a/lib/carbon/client.py +++ b/lib/carbon/client.py @@ -535,7 +535,7 @@ def __init__(self, router): if setUpRandomResolver: setUpRandomResolver(reactor) else: - print("Import error, you probably need Twisted >= 17.1.0 for using DESTINATION_POOL_REPLICAS.") + print("Import error, Twisted >= 17.1.0 needed for using DESTINATION_POOL_REPLICAS.") raise SystemExit(1) self.router = router