fix logic so threads do an orderly shutdown

basically the issue was that the main loop received the SIGINT
and therefore broke out before reaching the parts of the code
that care about bringing down the child threads.

therefore there's now a finish() method that needs to be called
after stop().

because sqlite dbs insists to be used from the thread that created
the object, the DB cleanup operation are done from the thread
that controls it.

for standalone operation, in order to keep the main thread alive,
an additional run() method is used. this is not necessary when
used via ppf.py.
This commit is contained in:
rofl0r
2019-01-05 17:13:39 +00:00
parent bb3da7122e
commit af8f82924f
2 changed files with 47 additions and 20 deletions

10
ppf.py
View File

@@ -176,7 +176,7 @@ if __name__ == '__main__':
# start proxy watcher
if config.watchd_threads > 0:
watcherd = proxywatchd.Proxywatchd()
watcherd.run_background()
watcherd.start()
else:
watcherd = None
@@ -191,11 +191,9 @@ if __name__ == '__main__':
else: time.sleep(10)
except KeyboardInterrupt:
print "XXXXXX"
if watcherd: watcherd.stop()
if watcherd:
watcherd.stop()
watcherd.finish()
break
print '\r',
# stop things
#if watcherd: watcherd.stop()