pep8 issues and threading with daemon=True

This commit is contained in:
Dirk Alders 2022-12-21 14:25:50 +01:00
parent 7583bb5f3b
commit af35e83d1f

View File

@ -159,13 +159,14 @@ class threaded_queue(queue):
.. literalinclude:: task/_examples_/threaded_queue.log .. literalinclude:: task/_examples_/threaded_queue.log
""" """
def __init__(self, expire=False): def __init__(self, expire=False):
queue.__init__(self, expire=expire) queue.__init__(self, expire=expire)
self.thread = None self.thread = None
def run(self): def run(self):
if self.thread is None: if self.thread is None:
self.thread = threading.Thread(target=self._start, args=()) self.thread = threading.Thread(target=self._start, args=(), daemon=True)
self.thread.daemon = True # Daemonize thread self.thread.daemon = True # Daemonize thread
self.thread.start() # Start the execution self.thread.start() # Start the execution
@ -206,6 +207,7 @@ class periodic(object):
.. literalinclude:: task/_examples_/periodic.log .. literalinclude:: task/_examples_/periodic.log
""" """
def __init__(self, cycle_time, callback, *args, **kwargs): def __init__(self, cycle_time, callback, *args, **kwargs):
self._lock = threading.Lock() self._lock = threading.Lock()
self._timer = None self._timer = None
@ -253,6 +255,7 @@ class periodic(object):
self._timer = threading.Timer(0, self._start) self._timer = threading.Timer(0, self._start)
else: else:
self._timer = threading.Timer(self.cycle_time, self._start) self._timer = threading.Timer(self.cycle_time, self._start)
self._timer.daemon = True
self._timer.start() self._timer.start()
self._lock.release() self._lock.release()
@ -281,6 +284,7 @@ class delayed(periodic):
.. literalinclude:: task/_examples_/delayed.log .. literalinclude:: task/_examples_/delayed.log
""" """
def run(self): def run(self):
""" """
This starts the timer for the delayed execution. This starts the timer for the delayed execution.
@ -329,12 +333,14 @@ class crontab(periodic):
""" """
class all_match(set): class all_match(set):
"""Universal set - match everything""" """Universal set - match everything"""
def __contains__(self, item): def __contains__(self, item):
(item) (item)
return True return True
def __init__(self, minute, hour, day_of_month, month, day_of_week, callback, *args, **kwargs): def __init__(self, minute, hour, day_of_month, month, day_of_week, callback, *args, **kwargs):
self.set_trigger_conditions(minute or crontab.ANY, hour or crontab.ANY, day_of_month or crontab.ANY, month or crontab.ANY, day_of_week or crontab.ANY) self.set_trigger_conditions(minute or crontab.ANY, hour or crontab.ANY,
day_of_month or crontab.ANY, month or crontab.ANY, day_of_week or crontab.ANY)
self.callback = callback self.callback = callback
self.args = args self.args = args
self.kwargs = kwargs self.kwargs = kwargs
@ -369,7 +375,7 @@ class crontab(periodic):
def __conv_to_set__(self, obj): def __conv_to_set__(self, obj):
if obj is crontab.ANY: if obj is crontab.ANY:
return self.all_match() return self.all_match()
elif isinstance(obj, (int, long) if sys.version_info < (3,0) else (int)): elif isinstance(obj, (int, long) if sys.version_info < (3, 0) else (int)):
return set([obj]) return set([obj])
else: else:
return set(obj) return set(obj)