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
"""
def __init__(self, expire=False):
queue.__init__(self, expire=expire)
self.thread = None
def run(self):
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.start() # Start the execution
@ -206,6 +207,7 @@ class periodic(object):
.. literalinclude:: task/_examples_/periodic.log
"""
def __init__(self, cycle_time, callback, *args, **kwargs):
self._lock = threading.Lock()
self._timer = None
@ -253,6 +255,7 @@ class periodic(object):
self._timer = threading.Timer(0, self._start)
else:
self._timer = threading.Timer(self.cycle_time, self._start)
self._timer.daemon = True
self._timer.start()
self._lock.release()
@ -281,6 +284,7 @@ class delayed(periodic):
.. literalinclude:: task/_examples_/delayed.log
"""
def run(self):
"""
This starts the timer for the delayed execution.
@ -329,12 +333,14 @@ class crontab(periodic):
"""
class all_match(set):
"""Universal set - match everything"""
def __contains__(self, item):
(item)
return True
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.args = args
self.kwargs = kwargs
@ -369,7 +375,7 @@ class crontab(periodic):
def __conv_to_set__(self, obj):
if obj is crontab.ANY:
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])
else:
return set(obj)