From 68441917d9316396b3d04d603eee381a78b35529 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Mon, 13 Aug 2018 08:03:34 -0600 Subject: [PATCH] make only as many threads as necessary --- connmonitor/connmonitor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/connmonitor/connmonitor.py b/connmonitor/connmonitor.py index ec24a30..4a0d27e 100755 --- a/connmonitor/connmonitor.py +++ b/connmonitor/connmonitor.py @@ -96,7 +96,9 @@ def run(self): self.jsonHdr = '{"addr":"%s", "name":"%s", %%s}' self.jsonHdr %= (self.host[0], self.hostname) - with multiprocessing.pool.ThreadPool(3) as pool: + numThreads = sum(int(bool(x)) for x in (self.conf.PING, self.conf.TRACE, self.conf.SCAN)) + + with multiprocessing.pool.ThreadPool(numThreads) as pool: try: waitables = [] if self.conf.SCAN: