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