Add _use_daemons flag to XMLStream to run all threads in daemon mode.

This WILL make the Python interpreter produce exceptions on shutdown.
This commit is contained in:
Lance Stout 2012-04-20 15:19:56 -07:00
parent cb2469322b
commit 8ee30179ea
2 changed files with 6 additions and 2 deletions

View File

@ -121,7 +121,7 @@ class Scheduler(object):
#: Lock for accessing the task queue. #: Lock for accessing the task queue.
self.schedule_lock = threading.RLock() self.schedule_lock = threading.RLock()
def process(self, threaded=True): def process(self, threaded=True, daemon=False):
"""Begin accepting and processing scheduled tasks. """Begin accepting and processing scheduled tasks.
:param bool threaded: Indicates if the scheduler should execute :param bool threaded: Indicates if the scheduler should execute
@ -130,6 +130,7 @@ class Scheduler(object):
if threaded: if threaded:
self.thread = threading.Thread(name='scheduler_process', self.thread = threading.Thread(name='scheduler_process',
target=self._process) target=self._process)
self.thread.daemon = daemon
self.thread.start() self.thread.start()
else: else:
self._process() self._process()

View File

@ -282,6 +282,7 @@ class XMLStream(object):
self.__event_handlers = {} self.__event_handlers = {}
self.__event_handlers_lock = threading.Lock() self.__event_handlers_lock = threading.Lock()
self.__filters = {'in': [], 'out': [], 'out_sync': []} self.__filters = {'in': [], 'out': [], 'out_sync': []}
self._use_daemons = False
self._id = 0 self._id = 0
self._id_lock = threading.Lock() self._id_lock = threading.Lock()
@ -1206,10 +1207,11 @@ class XMLStream(object):
else: else:
threaded = kwargs.get('threaded', True) threaded = kwargs.get('threaded', True)
self.scheduler.process(threaded=True) self.scheduler.process(threaded=True, daemon=self._use_daemons)
def start_thread(name, target): def start_thread(name, target):
self.__thread[name] = threading.Thread(name=name, target=target) self.__thread[name] = threading.Thread(name=name, target=target)
self.__thread[name].daemon = self._use_daemons
self.__thread[name].start() self.__thread[name].start()
for t in range(0, HANDLER_THREADS): for t in range(0, HANDLER_THREADS):
@ -1451,6 +1453,7 @@ class XMLStream(object):
name="Event_%s" % str(func), name="Event_%s" % str(func),
target=self._threaded_event_wrapper, target=self._threaded_event_wrapper,
args=(func, args)) args=(func, args))
x.daemon = self._use_daemons
x.start() x.start()
else: else:
func(*args) func(*args)