1
0

clean implementation of daemon threads

This commit is contained in:
ThomasV
2015-03-13 23:04:29 +01:00
parent 58f9ab3492
commit 72688a5cfa
8 changed files with 53 additions and 111 deletions

View File

@@ -4,6 +4,7 @@ import shutil
from datetime import datetime
import urlparse
import urllib
import threading
class NotEnoughFunds(Exception): pass
@@ -20,6 +21,30 @@ class MyEncoder(json.JSONEncoder):
return super(MyEncoder, self).default(obj)
class DaemonThread(threading.Thread):
""" daemon thread that terminates cleanly """
def __init__(self):
threading.Thread.__init__(self)
self.parent_thread = threading.currentThread()
self.running = False
self.running_lock = threading.Lock()
def start(self):
with self.running_lock:
self.running = True
return threading.Thread.start(self)
def is_running(self):
with self.running_lock:
return self.running and self.parent_thread.is_alive()
def stop(self):
with self.running_lock:
self.running = False
is_verbose = False
def set_verbosity(b):
global is_verbose