From 74d9d965bb3cf7bfdc8d88ab1a8d308b686c6a14 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Sat, 5 Jan 2019 18:14:41 +0000 Subject: [PATCH] proxywatchd: always use a new mysql obj could prevent memleaks, also helps thread-ownership issues. --- proxywatchd.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/proxywatchd.py b/proxywatchd.py index 8c3db48..3970277 100644 --- a/proxywatchd.py +++ b/proxywatchd.py @@ -132,13 +132,18 @@ class Proxywatchd(): wt.term() self.collect_work() self.submit_collected() - self.mysqlite.close() self.stopped.set() def finish(self): if not self.in_background: self._cleanup() while not self.stopped.is_set(): time.sleep(0.1) + def _prep_db(self): + self.mysqlite = mysqlite.mysqlite(config.database, str) + def _close_db(self): + if self.mysqlite: + self.mysqlite.close() + self.mysqlite = None def __init__(self): config.load() self.in_background = False @@ -147,11 +152,10 @@ class Proxywatchd(): self.stopped = threading.Event() # create table if needed - self.mysqlite = mysqlite.mysqlite(config.database, str) + self._prep_db() self.mysqlite.execute('CREATE TABLE IF NOT EXISTS proxylist (proxy BLOB, country BLOB, added INT, failed INT, tested INT, source BLOB, dronebl INT, proto TEXT, duration INT)') self.mysqlite.commit() - self.mysqlite.close() - self.mysqlite = None + self._close_db() self.submit_after = 200 # number of collected jobs before writing db self.echoise = time.time() - 3600; @@ -160,21 +164,25 @@ class Proxywatchd(): self.collected = [] def prepare_jobs(self): + self._prep_db() q = 'SELECT proxy,proto,failed FROM proxylist WHERE failed