signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
@abstractmethod<EOL><INDENT>@verify_value(decorated_function=lambda x: callable(x))<EOL>def get_cache(self, decorated_function, *args, **kwargs):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Get cache entry (:class:`.WCacheStorage.CacheEntry`) for the specified arguments :param decorated_function: called function (original) :param args: args with which function is called :param kwargs: kwargs with which function is called :return: WCacheStorage.CacheEntry
f9832:c0:m1
@abstractmethod<EOL><INDENT>@verify_value(decorated_function=lambda x: x is None or callable(x))<EOL>def clear(self, decorated_function=None):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Remove results from this storage :param decorated_function: if specified, then results will be removed for this function only :return: None
f9832:c0:m2
@verify_value('<STR_LIT>', decorated_function=lambda x: callable(x))<EOL><INDENT>def has(self, decorated_function, *args, **kwargs):<DEDENT>
return self.get_cache(decorated_function, *args, **kwargs).has_value<EOL>
Check if there is a result for given function :param decorated_function: called function (original) :param args: args with which function is called :param kwargs: kwargs with which function is called :return: None
f9832:c0:m3
@verify_value('<STR_LIT>', decorated_function=lambda x: callable(x))<EOL><INDENT>def get_result(self, decorated_function, *args, **kwargs):<DEDENT>
cache_entry = self.get_cache(decorated_function, *args, **kwargs)<EOL>if cache_entry.has_value is False:<EOL><INDENT>raise WCacheStorage.CacheMissedException('<STR_LIT>')<EOL><DEDENT>return cache_entry.cached_value<EOL>
Get result from storage for specified function. Will raise an exception (:class:`.WCacheStorage.CacheMissedException`) if there is no cached result. :param decorated_function: called function (original) :param args: args with which function is called :param kwargs: kwargs with which function is called :return: (any type, even None)
f9832:c0:m4
def __init__(self):
self._storage = {}<EOL>
Construct new storage
f9832:c1:m0
@verify_value(decorated_function=lambda x: callable(x))<EOL><INDENT>def put(self, result, decorated_function, *args, **kwargs):<DEDENT>
self._storage[decorated_function] = result<EOL>
:meth:`WCacheStorage.put` method implementation
f9832:c1:m1
@verify_value(decorated_function=lambda x: callable(x))<EOL><INDENT>def has(self, decorated_function, *args, **kwargs):<DEDENT>
return decorated_function in self._storage.keys()<EOL>
:meth:`WCacheStorage.has` method implementation
f9832:c1:m2
@verify_value(decorated_function=lambda x: callable(x))<EOL><INDENT>def get_result(self, decorated_function, *args, **kwargs):<DEDENT>
try:<EOL><INDENT>return self._storage[decorated_function]<EOL><DEDENT>except KeyError as e:<EOL><INDENT>raise WCacheStorage.CacheMissedException('<STR_LIT>') from e<EOL><DEDENT>
:meth:`WCacheStorage.get_result` method implementation
f9832:c1:m3
@verify_value('<STR_LIT>', decorated_function=lambda x: callable(x))<EOL><INDENT>def get_cache(self, decorated_function, *args, **kwargs):<DEDENT>
has_value = self.has(decorated_function, *args, **kwargs)<EOL>cached_value = None<EOL>if has_value is True:<EOL><INDENT>cached_value = self.get_result(decorated_function, *args, **kwargs)<EOL><DEDENT>return WCacheStorage.CacheEntry(has_value=has_value, cached_value=cached_value)<EOL>
:meth:`WCacheStorage.get_cache` method implementation
f9832:c1:m4
@verify_value(decorated_function=lambda x: x is None or callable(x))<EOL><INDENT>def clear(self, decorated_function=None):<DEDENT>
if decorated_function is not None and decorated_function in self._storage:<EOL><INDENT>self._storage.pop(decorated_function)<EOL><DEDENT>else:<EOL><INDENT>self._storage.clear()<EOL><DEDENT>
:meth:`WCacheStorage.clear` method implementation
f9832:c1:m5
@verify_type(statistic=bool)<EOL><INDENT>def __init__(self, cache_record_cls=None, statistic=False):<DEDENT>
self._storage = {}<EOL>self._cache_record_cls = None<EOL>if cache_record_cls is not None:<EOL><INDENT>if issubclass(cache_record_cls, WInstanceSingletonCacheStorage.InstanceCacheRecord) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>self._cache_record_cls = cache_record_cls<EOL><DEDENT>else:<EOL><INDENT>self._cache_record_cls = WInstanceSingletonCacheStorage.InstanceCacheRecord<EOL><DEDENT>self.__statistic = statistic<EOL>self.__cache_missed = <NUM_LIT:0> if self.__statistic is True else None<EOL>self.__cache_hit = <NUM_LIT:0> if self.__statistic is True else None<EOL>
Construct new storage :param cache_record_cls: class for keeping cache :param statistic: whether to store statistics about cache hits and misses or not
f9832:c2:m0
@verify_value('<STR_LIT>', decorated_function=lambda x: callable(x))<EOL><INDENT>def __check(self, decorated_function, *args, **kwargs):<DEDENT>
<EOL>if len(args) >= <NUM_LIT:1>:<EOL><INDENT>obj = args[<NUM_LIT:0>]<EOL>function_name = decorated_function.__name__<EOL>if hasattr(obj, function_name) is True:<EOL><INDENT>fn = getattr(obj, function_name)<EOL>if callable(fn) and fn.__self__ == obj:<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>raise RuntimeError('<STR_LIT>')<EOL>
Check whether function is a bounded method or not. If check fails then exception is raised :param decorated_function: called function (original) :param args: args with which function is called :param kwargs: kwargs with which function is called :return: None
f9832:c2:m1
@verify_value(decorated_function=lambda x: callable(x))<EOL><INDENT>def put(self, result, decorated_function, *args, **kwargs):<DEDENT>
self.__check(decorated_function, *args, **kwargs)<EOL>ref = weakref.ref(args[<NUM_LIT:0>])<EOL>if decorated_function not in self._storage:<EOL><INDENT>cache_entry = self._cache_record_cls.create(result, decorated_function, *args, **kwargs)<EOL>self._storage[decorated_function] = [{'<STR_LIT>': ref, '<STR_LIT:result>': cache_entry}]<EOL><DEDENT>else:<EOL><INDENT>instance_found = False<EOL>for i in self._storage[decorated_function]:<EOL><INDENT>if i['<STR_LIT>']() == args[<NUM_LIT:0>]:<EOL><INDENT>cache_entry = i['<STR_LIT:result>']<EOL>cache_entry.update(result, *args, **kwargs)<EOL>instance_found = True<EOL>break<EOL><DEDENT><DEDENT>if instance_found is False:<EOL><INDENT>cache_entry = self._cache_record_cls.create(result, decorated_function, *args, **kwargs)<EOL>self._storage[decorated_function].append({'<STR_LIT>': ref, '<STR_LIT:result>': cache_entry})<EOL><DEDENT><DEDENT>def finalize_ref():<EOL><INDENT>if decorated_function in self._storage:<EOL><INDENT>fn_list = self._storage[decorated_function]<EOL>if len(fn_list) == <NUM_LIT:1> and fn_list[<NUM_LIT:0>]['<STR_LIT>'] == ref:<EOL><INDENT>del self._storage[decorated_function]<EOL><DEDENT>for i in range(len(fn_list)):<EOL><INDENT>if fn_list[i]['<STR_LIT>'] == ref:<EOL><INDENT>fn_list.pop(i)<EOL>return<EOL><DEDENT><DEDENT><DEDENT><DEDENT>weakref.finalize(args[<NUM_LIT:0>], finalize_ref)<EOL>
:meth:`WCacheStorage.put` method implementation
f9832:c2:m2
@verify_value(decorated_function=lambda x: callable(x))<EOL><INDENT>def get_cache(self, decorated_function, *args, **kwargs):<DEDENT>
self.__check(decorated_function, *args, **kwargs)<EOL>if decorated_function in self._storage:<EOL><INDENT>for i in self._storage[decorated_function]:<EOL><INDENT>if i['<STR_LIT>']() == args[<NUM_LIT:0>]:<EOL><INDENT>result = i['<STR_LIT:result>'].cache_entry(*args, **kwargs)<EOL>if self.__statistic is True:<EOL><INDENT>if result.has_value is True:<EOL><INDENT>self.__cache_hit += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>self.__cache_missed += <NUM_LIT:1><EOL><DEDENT><DEDENT>return result<EOL><DEDENT><DEDENT><DEDENT>if self.__statistic is True:<EOL><INDENT>self.__cache_missed += <NUM_LIT:1><EOL><DEDENT>return WCacheStorage.CacheEntry()<EOL>
:meth:`WCacheStorage.get_cache` method implementation
f9832:c2:m3
@verify_value(decorated_function=lambda x: x is None or callable(x))<EOL><INDENT>def clear(self, decorated_function=None):<DEDENT>
if decorated_function is not None and decorated_function in self._storage:<EOL><INDENT>self._storage.pop(decorated_function)<EOL><DEDENT>else:<EOL><INDENT>self._storage.clear()<EOL><DEDENT>if self.__statistic is True:<EOL><INDENT>self.__cache_missed = <NUM_LIT:0><EOL>self.__cache_hit = <NUM_LIT:0><EOL><DEDENT>
:meth:`WCacheStorage.clear` method implementation (Clears statistics also)
f9832:c2:m4
def cache_missed(self):
return self.__cache_missed<EOL>
Return cache misses (return None if class was constructed without 'statistic' flag) :return: int or None
f9832:c2:m5
def cache_hit(self):
return self.__cache_hit<EOL>
Return cache hits (return None if class was constructed without 'statistic' flag) :return: int or None
f9832:c2:m6
def __init__(cls, name, bases, namespace):
if cls.__auto_registry__ is True:<EOL><INDENT>if cls.__registry__ is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if issubclass(cls.__registry__, WTaskDependencyRegistry) is False:<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if cls.__registry_tag__ is None:<EOL><INDENT>if cls.__registry__.__skip_none_registry_tag__ is False:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>elif isinstance(cls.__registry_tag__, str) is False:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT><DEDENT>WRegisteredTask.__init__(cls, name, bases, namespace)<EOL>
Construct new class. Derived class must redefine __registry__ and __registry_tag__ properties. In order to start dependency task automatically, property __dependency__ must be redefined. It is highly important, that derived class method :meth:`.WDependentTask.start_dependent_task` will be able to construct and start this task. :param name: as name in type(cls, name, bases, namespace) :param bases: as bases in type(cls, name, bases, namespace) :param namespace: as namespace in type(cls, name, bases, namespace)
f9833:c0:m0
def start_dependent_task(cls):
task = cls()<EOL>task.start()<EOL>return task<EOL>
Start this task and return its instance :return: WTask
f9833:c0:m1
def __init__(self):
WTaskRegistryStorage.__init__(self)<EOL>self.__started = []<EOL>
Construct new storage
f9833:c1:m0
@verify_type(task_cls=WDependentTask)<EOL><INDENT>def add(self, task_cls):<DEDENT>
return WTaskRegistryStorage.add(self, task_cls)<EOL>
Add task to this storage. Multiple tasks with the same tag are not allowed :param task_cls: task to add :return: None
f9833:c1:m1
@verify_subclass(task_cls=WTask)<EOL><INDENT>@verify_type(task_cls=WDependentTask)<EOL>def dependency_check(self, task_cls, skip_unresolved=False):<DEDENT>
def check(check_task_cls, global_dependencies):<EOL><INDENT>if check_task_cls.__registry_tag__ in global_dependencies:<EOL><INDENT>raise RuntimeError('<STR_LIT>' % task_cls.__registry_tag__)<EOL><DEDENT>dependencies = global_dependencies.copy()<EOL>dependencies.append(check_task_cls.__registry_tag__)<EOL>for dependency in check_task_cls.__dependency__:<EOL><INDENT>dependent_task = self.tasks_by_tag(dependency)<EOL>if dependent_task is None and skip_unresolved is False:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>" %<EOL>(task_cls.__registry_tag__, dependency)<EOL>)<EOL><DEDENT>if dependent_task is not None:<EOL><INDENT>check(dependent_task, dependencies)<EOL><DEDENT><DEDENT><DEDENT>check(task_cls, [])<EOL>
Check dependency of task for irresolvable conflicts (like task to task mutual dependency) :param task_cls: task to check :param skip_unresolved: flag controls this method behaviour for tasks that could not be found. \ When False, method will raise an exception if task tag was set in dependency and the related task \ wasn't found in registry. When True that unresolvable task will be omitted :return: None
f9833:c1:m2
def started_tasks(self, task_registry_id=None, task_cls=None):
if task_registry_id is not None:<EOL><INDENT>task = None<EOL>for registered_task in self.__started:<EOL><INDENT>if registered_task.__registry_tag__ == task_registry_id:<EOL><INDENT>task = registered_task<EOL><DEDENT><DEDENT>if task_cls is not None and task is not None:<EOL><INDENT>if isinstance(task, task_cls) is True:<EOL><INDENT>return task<EOL><DEDENT>return None<EOL><DEDENT>return task<EOL><DEDENT>result = filter(lambda x: x is not None, self.__started)<EOL>if task_cls is not None:<EOL><INDENT>result = filter(lambda x: isinstance(x, task_cls), result)<EOL><DEDENT>return tuple(result)<EOL>
Return tasks that was started. Result way be filtered by the given arguments. :param task_registry_id: if it is specified, then try to return single task which id is the same as \ this value. :param task_cls: if it is specified then result will be consists of this subclass only :return: None or WTask or tuple of WTask
f9833:c1:m3
@verify_type(task_tag=str, skip_unresolved=bool)<EOL><INDENT>def start_task(self, task_tag, skip_unresolved=False):<DEDENT>
if self.started_tasks(task_registry_id=task_tag) is not None:<EOL><INDENT>return<EOL><DEDENT>task_cls = self.tasks_by_tag(task_tag)<EOL>if task_cls is None:<EOL><INDENT>raise RuntimeError("<STR_LIT>" % task_tag)<EOL><DEDENT>self.dependency_check(task_cls, skip_unresolved=skip_unresolved)<EOL>def start_dependency(start_task_cls):<EOL><INDENT>for dependency in start_task_cls.__dependency__:<EOL><INDENT>if self.started_tasks(task_registry_id=dependency) is not None:<EOL><INDENT>continue<EOL><DEDENT>dependent_task = self.tasks_by_tag(dependency)<EOL>if dependent_task is not None:<EOL><INDENT>start_dependency(dependent_task)<EOL><DEDENT><DEDENT>self.__started.append(start_task_cls.start_dependent_task())<EOL><DEDENT>start_dependency(task_cls)<EOL>
Check dependency for the given task_tag and start task. For dependency checking see :meth:`.WTaskDependencyRegistryStorage.dependency_check`. If task is already started then it must be stopped before it will be started again. :param task_tag: task to start. Any required dependencies will be started automatically. :param skip_unresolved: flag controls this method behaviour for tasks that could not be found. \ When False, method will raise an exception if task tag was set in dependency and the related task \ wasn't found in registry. When True that unresolvable task will be omitted :return: None
f9833:c1:m4
@verify_type(task_tag=str, stop_dependent=bool, stop_requirements=bool)<EOL><INDENT>def stop_task(self, task_tag, stop_dependent=True, stop_requirements=False):<DEDENT>
<EOL>task = self.started_tasks(task_registry_id=task_tag)<EOL>if task is None:<EOL><INDENT>return<EOL><DEDENT>def stop(task_to_stop):<EOL><INDENT>if task_to_stop in self.__started:<EOL><INDENT>if isinstance(task_to_stop, WStoppableTask) is True:<EOL><INDENT>task_to_stop.stop()<EOL><DEDENT>self.__started.remove(task_to_stop)<EOL><DEDENT><DEDENT>def stop_dependency(task_to_stop):<EOL><INDENT>deeper_dependencies = []<EOL>for dependent_task in self.__started:<EOL><INDENT>if task_to_stop.__registry_tag__ in dependent_task.__class__.__dependency__:<EOL><INDENT>deeper_dependencies.append(dependent_task)<EOL><DEDENT><DEDENT>for dependent_task in deeper_dependencies:<EOL><INDENT>stop_dependency(dependent_task)<EOL><DEDENT>stop(task_to_stop)<EOL><DEDENT>def calculate_requirements(task_to_stop, cross_requirements=False):<EOL><INDENT>requirements = set()<EOL>for dependent_task in self.__started:<EOL><INDENT>if dependent_task.__class__.__registry_tag__ in task_to_stop.__class__.__dependency__:<EOL><INDENT>requirements.add(dependent_task)<EOL><DEDENT><DEDENT>if cross_requirements is True:<EOL><INDENT>return requirements<EOL><DEDENT>result = set()<EOL>for task_a in requirements:<EOL><INDENT>requirement_match = False<EOL>for task_b in requirements:<EOL><INDENT>if task_a.__class__.__registry_tag__ in task_b.__class__.__dependency__:<EOL><INDENT>requirement_match = True<EOL>break<EOL><DEDENT><DEDENT>if requirement_match is False:<EOL><INDENT>result.add(task_a)<EOL><DEDENT><DEDENT>return result<EOL><DEDENT>def calculate_priorities(task_to_stop, *extra_tasks, current_result=None, requirements_left=None):<EOL><INDENT>if current_result is None:<EOL><INDENT>current_result = []<EOL><DEDENT>tasks_to_stop = [task_to_stop]<EOL>if len(extra_tasks) > <NUM_LIT:0>:<EOL><INDENT>tasks_to_stop.extend(extra_tasks)<EOL><DEDENT>current_result.append(list(tasks_to_stop))<EOL>all_requirements = calculate_requirements(tasks_to_stop[<NUM_LIT:0>], cross_requirements=True)<EOL>nested_requirements = calculate_requirements(tasks_to_stop[<NUM_LIT:0>])<EOL>for dependent_task in tasks_to_stop[<NUM_LIT:1>:]:<EOL><INDENT>nested_requirements = nested_requirements.union(calculate_requirements(dependent_task))<EOL>all_requirements.update(calculate_requirements(dependent_task, cross_requirements=True))<EOL><DEDENT>all_requirements = all_requirements.difference(nested_requirements)<EOL>if requirements_left is not None:<EOL><INDENT>requirements_left = requirements_left.difference(all_requirements)<EOL>nested_requirements.update(requirements_left)<EOL><DEDENT>if len(nested_requirements) == <NUM_LIT:0>:<EOL><INDENT>return current_result<EOL><DEDENT>return calculate_priorities(<EOL>*list(nested_requirements), current_result=current_result, requirements_left=all_requirements<EOL>)<EOL><DEDENT>if stop_dependent is True:<EOL><INDENT>stop_dependency(task)<EOL><DEDENT>if stop_requirements is True:<EOL><INDENT>for task_list in calculate_priorities(task):<EOL><INDENT>for single_task in task_list:<EOL><INDENT>stop(single_task)<EOL><DEDENT><DEDENT><DEDENT>if stop_dependent is not True: <EOL><INDENT>stop(task)<EOL><DEDENT>
Stop task with the given task tag. If task already stopped, then nothing happens. :param task_tag: task to stop :param stop_dependent: if True, then every task, that require the given task as dependency, will be \ stopped before. :param stop_requirements: if True, then every task, that is required as dependency for the given task, \ will be stopped after. :return: None
f9833:c1:m5
@classmethod<EOL><INDENT>def registry_storage(cls):<DEDENT>
if cls.__registry_storage__ is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if isinstance(cls.__registry_storage__, WTaskDependencyRegistryStorage) is False:<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>return cls.__registry_storage__<EOL>
Get registry storage :return: WTaskDependencyRegistryStorage
f9833:c2:m0
@classmethod<EOL><INDENT>def start_task(cls, task_tag, skip_unresolved=False):<DEDENT>
registry = cls.registry_storage()<EOL>registry.start_task(task_tag, skip_unresolved=skip_unresolved)<EOL>
Start task from registry :param task_tag: same as in :meth:`.WTaskDependencyRegistryStorage.start_task` method :param skip_unresolved: same as in :meth:`.WTaskDependencyRegistryStorage.start_task` method :return: None
f9833:c2:m1
@classmethod<EOL><INDENT>def stop_task(cls, task_tag, stop_dependent=True, stop_requirements=False):<DEDENT>
registry = cls.registry_storage()<EOL>registry.stop_task(task_tag, stop_dependent=stop_dependent, stop_requirements=stop_requirements)<EOL>
Stop started task from registry :param task_tag: same as in :meth:`.WTaskDependencyRegistryStorage.stop_task` method :param stop_dependent: same as in :meth:`.WTaskDependencyRegistryStorage.stop_task` method :param stop_requirements: same as in :meth:`.WTaskDependencyRegistryStorage.stop_task` method :return: None
f9833:c2:m2
@classmethod<EOL><INDENT>def all_stop(cls):<DEDENT>
for task_tag in cls.registry_storage().tags():<EOL><INDENT>cls.stop_task(task_tag)<EOL><DEDENT>
Stop every task started within this registry :return: None
f9833:c2:m3
@abstractmethod<EOL><INDENT>def start(self):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Start this task :return: None
f9834:c0:m0
@abstractmethod<EOL><INDENT>def stop(self):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Stop this task (graceful shutdown) :return: None
f9834:c1:m0
@abstractmethod<EOL><INDENT>def terminate(self):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Terminate this task (rough shutdown) :return: None
f9834:c2:m0
def stop(self):
pass<EOL>
Stop this task. This implementation does nothing. :return: None
f9834:c3:m1
@abstractmethod<EOL><INDENT>@verify_type(task=WThreadTask, event_details=(str, None))<EOL>def register_start(self, task, event_details=None):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Store start event :param task: task that is starting :param event_details: (optional) event details - any kind of data related to the given task and start \ event :return: None
f9835:c1:m0
@abstractmethod<EOL><INDENT>@verify_type(task=WThreadTask, event_details=(str, None))<EOL>def register_stop(self, task, event_details=None):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Store stop event :param task: task that stopped :param event_details: (optional) event details - any kind of data related to the given task and stop \ event :return: None
f9835:c1:m1
@abstractmethod<EOL><INDENT>@verify_type(task=WThreadTask, event_details=(str, None))<EOL>def register_termination(self, task, event_details=None):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Store termination event :param task: task that was terminated :param event_details: (optional) event details - any kind of data related to the given task and \ termination event :return: None
f9835:c1:m2
@abstractmethod<EOL><INDENT>@verify_type(task=WThreadTask, raised_exception=Exception, exception_details=str, event_details=(str, None))<EOL>def register_exception(self, task, raised_exception, exception_details, event_details=None):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Store exception event :param task: task that was terminated by unhandled exception :param raised_exception: unhandled exception :param exception_details: any kind of data related to the raised exception :param event_details: (optional) event details - any kind of data related to the given task and exception event :return: None
f9835:c1:m3
@abstractmethod<EOL><INDENT>@verify_type(task=WThreadTask, event_details=(str, None))<EOL>def register_wait(self, task, event_details=None):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Store event of task postponing (this event is used in a scheduler classes) :param task: task that was postponed :param event_details: (optional) event details - any kind of data related to the given task and postponing event :return: None
f9835:c1:m4
@abstractmethod<EOL><INDENT>@verify_type(task=WThreadTask, event_details=(str, None))<EOL>def register_drop(self, task, event_details=None):<DEDENT>
raise NotImplementedError('<STR_LIT>')<EOL>
Store event of task drop (this event is used in a scheduler classes) :param task: task that was dropped :param event_details: (optional) event details - any kind of data related to the given task and event of task drop :return: None
f9835:c1:m5
@verify_type('<STR_LIT>', thread_name=(str, None), join_on_stop=bool, thread_join_timeout=(int, float, None))<EOL><INDENT>@verify_type(tracker_storage=(WThreadTrackerInfoStorageProto, None), track_start=bool, track_stop=bool)<EOL>@verify_type(track_termination=bool, track_exception=bool)<EOL>def __init__(<EOL>self, tracker_storage=None, thread_name=None, join_on_stop=True, thread_join_timeout=None,<EOL>track_start=True, track_stop=True, track_termination=True, track_exception=True<EOL>):<DEDENT>
WThreadTask.__init__(<EOL>self,<EOL>thread_name=thread_name,<EOL>join_on_stop=join_on_stop,<EOL>ready_to_stop=True,<EOL>thread_join_timeout=thread_join_timeout<EOL>)<EOL>self.__tracker = tracker_storage<EOL>self.__track_start = track_start<EOL>self.__track_stop = track_stop<EOL>self.__track_termination = track_termination<EOL>self.__track_exception = track_exception<EOL>
Create new tracker :param tracker_storage: storage that is used for registering eventd :param thread_name: same as 'thread_name' in :meth:`.WThreadTask.__init__` :param join_on_stop: same as 'join_on_stop' in :meth:`.WThreadTask.__init__` :param thread_join_timeout: same as 'thread_join_timeout' in :meth:`.WThreadTask.__init__` :param track_start: whether to register start event of this task or not :param track_stop: whether to register stop event of this task or not :param track_termination: whether to register termination event of this task or not :param track_exception: whether to register unhandled exception event or not
f9835:c2:m0
def tracker_storage(self):
return self.__tracker<EOL>
Return linked storage :return: WThreadTrackerInfoStorageProto or None
f9835:c2:m1
def track_start(self):
return self.__track_start<EOL>
Return True if this task is tracking "start-event" otherwise - False :return: bool
f9835:c2:m2
def track_stop(self):
return self.__track_stop<EOL>
Return True if this task is tracking "stop-event" otherwise - False :return: bool
f9835:c2:m3
def track_termination(self):
return self.__track_termination<EOL>
Return True if this task is tracking "termination-event" otherwise - False :return: bool
f9835:c2:m4
def track_exception(self):
return self.__track_exception<EOL>
Return True if this task is tracking unhandled exception event otherwise - False :return: bool
f9835:c2:m5
@verify_type(event=WTrackerEvents)<EOL><INDENT>def event_details(self, event):<DEDENT>
return None<EOL>
Return task details that should be registered with a tracker storage :param event: source event that requested details :return: str or None
f9835:c2:m6
def start(self):
tracker = self.tracker_storage()<EOL>if tracker is not None and self.track_start() is True:<EOL><INDENT>details = self.event_details(WTrackerEvents.start)<EOL>tracker.register_start(self, event_details=details)<EOL><DEDENT>WThreadTask.start(self)<EOL>
:meth:`.WThreadTask.start` implementation. Register (if required) start event by a tracker storage :return: None
f9835:c2:m7
def thread_stopped(self):
tracker = self.tracker_storage()<EOL>if tracker is not None:<EOL><INDENT>try:<EOL><INDENT>if self.ready_event().is_set() is True:<EOL><INDENT>if self.track_stop() is True:<EOL><INDENT>details = self.event_details(WTrackerEvents.stop)<EOL>tracker.register_stop(self, event_details=details)<EOL><DEDENT><DEDENT>elif self.exception_event().is_set() is False:<EOL><INDENT>if self.track_termination() is True:<EOL><INDENT>details = self.event_details(WTrackerEvents.termination)<EOL>tracker.register_termination(self, event_details=details)<EOL><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>self.thread_tracker_exception(e)<EOL><DEDENT><DEDENT>
:meth:`.WThreadTask.thread_stopped` implementation. Register (if required) stop and termination event by a tracker storage :return: None
f9835:c2:m8
@verify_type(raised_exception=Exception)<EOL><INDENT>def thread_exception(self, raised_exception):<DEDENT>
tracker = self.tracker_storage()<EOL>if tracker is not None:<EOL><INDENT>try:<EOL><INDENT>if self.track_exception() is True:<EOL><INDENT>details = self.event_details(WTrackerEvents.exception)<EOL>tracker.register_exception(<EOL>self,<EOL>raised_exception,<EOL>traceback.format_exc(),<EOL>event_details=details<EOL>)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>self.thread_tracker_exception(e)<EOL><DEDENT><DEDENT>
:meth:`.WThreadTask.thread_exception` implementation. Register (if required) unhandled exception event by a tracker storage :param raised_exception: unhandled exception :return: None
f9835:c2:m9
@verify_type(raised_exception=Exception)<EOL><INDENT>def thread_tracker_exception(self, raised_exception):<DEDENT>
print('<STR_LIT>' % str(raised_exception))<EOL>print('<STR_LIT>')<EOL>print(traceback.format_exc())<EOL>
Method is called whenever an exception is raised during registering a event :param raised_exception: raised exception :return: None
f9835:c2:m10
@verify_type(records_limit=(int, None), record_start=bool, record_stop=bool, record_termination=bool)<EOL><INDENT>@verify_type(record_exception=bool, record_wait=bool, record_drop=bool)<EOL>def __init__(<EOL>self, records_limit=None, record_start=True, record_stop=True, record_termination=True,<EOL>record_exception=True, record_wait=True, record_drop=True<EOL>):<DEDENT>
WCriticalResource.__init__(self)<EOL>WThreadTrackerInfoStorageProto.__init__(self)<EOL>self.__limit = records_limit<EOL>self.__registry = []<EOL>self.__record_start = record_start<EOL>self.__record_stop = record_stop<EOL>self.__record_termination = record_termination<EOL>self.__record_exception = record_exception<EOL>self.__record_wait = record_wait<EOL>self.__record_drop = record_drop<EOL>
Create new storage :param records_limit: number of records to keep (if record limit is reached - new record will overwrite the oldest one) :param record_start: whether to keep start events or not :param record_stop: whether to keep normal stop events or not :param record_termination: whether to keep termination stop events or not :param record_exception: whether to keep unhandled exceptions events or not :param record_wait: whether to keep postponing events or not :param record_drop: whether to keep drop events or not
f9835:c3:m0
def record_limit(self):
return self.__limit<EOL>
Return maximum number of records to keep :return: int or None (for no limit)
f9835:c3:m1
def record_start(self):
return self.__record_start<EOL>
Return True if this storage is saving start events, otherwise - False :return: bool
f9835:c3:m2
def record_stop(self):
return self.__record_stop<EOL>
Return True if this storage is saving normal stop events, otherwise - False :return: bool
f9835:c3:m3
def record_termination(self):
return self.__record_termination<EOL>
Return True if this storage is saving termination stop events, otherwise - False :return: bool
f9835:c3:m4
def record_exception(self):
return self.__record_exception<EOL>
Return True if this storage is saving unhandled exceptions events, otherwise - False :return: bool
f9835:c3:m5
def record_wait(self):
return self.__record_wait<EOL>
Return True if this storage is saving postponing events, otherwise - False :return: bool
f9835:c3:m6
def record_drop(self):
return self.__record_drop<EOL>
Return True if this storage is saving dropping events, otherwise - False :return: bool
f9835:c3:m7
def register_start(self, task, event_details=None):
if self.record_start() is True:<EOL><INDENT>record_type = WTrackerEvents.start<EOL>record = WSimpleTrackerStorage.Record(record_type, task, event_details=event_details)<EOL>self.__store_record(record)<EOL><DEDENT>
:meth:`.WSimpleTrackerStorage.register_start` method implementation
f9835:c3:m8
@verify_type(task=WThreadTask, details=(str, None))<EOL><INDENT>def register_stop(self, task, event_details=None):<DEDENT>
if self.record_stop() is True:<EOL><INDENT>record_type = WTrackerEvents.stop<EOL>record = WSimpleTrackerStorage.Record(record_type, task, event_details=event_details)<EOL>self.__store_record(record)<EOL><DEDENT>
:meth:`.WSimpleTrackerStorage.register_stop` method implementation
f9835:c3:m9
@verify_type(task=WThreadTask, details=(str, None))<EOL><INDENT>def register_termination(self, task, event_details=None):<DEDENT>
if self.record_termination() is True:<EOL><INDENT>record_type = WTrackerEvents.termination<EOL>record = WSimpleTrackerStorage.Record(record_type, task, event_details=event_details)<EOL>self.__store_record(record)<EOL><DEDENT>
:meth:`.WSimpleTrackerStorage.register_termination` method implementation
f9835:c3:m10
@verify_type(task=WThreadTask, raised_exception=Exception, exception_details=str, details=(str, None))<EOL><INDENT>def register_exception(self, task, raised_exception, exception_details, event_details=None):<DEDENT>
if self.record_exception() is True:<EOL><INDENT>record = WSimpleTrackerStorage.ExceptionRecord(<EOL>task, raised_exception, exception_details, event_details=event_details<EOL>)<EOL>self.__store_record(record)<EOL><DEDENT>
:meth:`.WSimpleTrackerStorage.register_exception` method implementation
f9835:c3:m11
@verify_type(task=WThreadTask, details=(str, None))<EOL><INDENT>def register_wait(self, task, event_details=None):<DEDENT>
if self.record_wait() is True:<EOL><INDENT>record_type = WTrackerEvents.wait<EOL>record = WSimpleTrackerStorage.Record(record_type, task, event_details=event_details)<EOL>self.__store_record(record)<EOL><DEDENT>
:meth:`.WSimpleTrackerStorage.register_wait` method implementation
f9835:c3:m12
@verify_type(task=WThreadTask, details=(str, None))<EOL><INDENT>def register_drop(self, task, event_details=None):<DEDENT>
if self.record_drop() is True:<EOL><INDENT>record_type = WTrackerEvents.drop<EOL>record = WSimpleTrackerStorage.Record(record_type, task, event_details=event_details)<EOL>self.__store_record(record)<EOL><DEDENT>
:meth:`.WSimpleTrackerStorage.register_drop` method implementation
f9835:c3:m13
@WCriticalResource.critical_section(timeout=__critical_section_timeout__)<EOL><INDENT>def __store_record(self, record):<DEDENT>
if isinstance(record, WSimpleTrackerStorage.Record) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>limit = self.record_limit()<EOL>if limit is not None and len(self.__registry) >= limit:<EOL><INDENT>self.__registry.pop(<NUM_LIT:0>)<EOL><DEDENT>self.__registry.append(record)<EOL>
Save record in a internal storage :param record: record to save :return: None
f9835:c3:m14
@WCriticalResource.critical_section(timeout=__critical_section_timeout__)<EOL><INDENT>def __registry_copy(self):<DEDENT>
return self.__registry.copy()<EOL>
Return copy of tracked events :return: list of WSimpleTrackerStorage.Record
f9835:c3:m15
def __iter__(self):
registry = self.__registry_copy()<EOL>while len(registry) > <NUM_LIT:0>:<EOL><INDENT>yield registry.pop(-<NUM_LIT:1>)<EOL><DEDENT>
Iterate over registered events (WSimpleTrackerStorage.Record). The newest record will be yield the first :return: generator
f9835:c3:m16
@verify_type(requested_events=WTrackerEvents)<EOL><INDENT>def last_record(self, task_uid, *requested_events):<DEDENT>
for record in self:<EOL><INDENT>if isinstance(record.thread_task, WScheduleTask) is False:<EOL><INDENT>continue<EOL><DEDENT>if record.thread_task.uid() == task_uid:<EOL><INDENT>if len(requested_events) == <NUM_LIT:0> or record.record_type in requested_events:<EOL><INDENT>return record<EOL><DEDENT><DEDENT><DEDENT>
Search over registered :class:`.WScheduleTask` instances and return the last record that matches search criteria. :param task_uid: uid of :class:`.WScheduleTask` instance :param requested_events: target events types :return: WSimpleTrackerStorage.Record or None
f9835:c3:m17
@verify_type('<STR_LIT>', task=WScheduleTask, task_group_id=(str, None))<EOL><INDENT>@verify_value('<STR_LIT>', on_drop=lambda x: x is None or callable(x))<EOL>@verify_value('<STR_LIT>', on_wait=lambda x: x is None or callable(x))<EOL>@verify_type(task=WThreadTracker)<EOL>@verify_type(track_wait=bool, track_drop=bool)<EOL>def __init__(<EOL>self, task, policy=None, task_group_id=None, on_drop=None, on_wait=None,<EOL>track_wait=True, track_drop=True<EOL>):<DEDENT>
WScheduleRecord.__init__(<EOL>self, task, policy=policy, task_group_id=task_group_id, on_drop=on_drop, on_wait=on_wait<EOL>)<EOL>self.__track_wait = track_wait<EOL>self.__track_drop = track_drop<EOL>
Create new schedule record, that may track schedule events :param task: same as task in :meth:`.WScheduleRecord.__init__` except it must be \ :class:`.WThreadTracker` instance :param policy: same as policy in :meth:`.WScheduleRecord.__init__` :param task_group_id: same as task_group_id in :meth:`.WScheduleRecord.__init__` :param on_drop: same as on_drop in :meth:`.WScheduleRecord.__init__` :param on_wait: same as on_wait in :meth:`.WScheduleRecord.__init__` :param track_wait: whether to register postponing event of this record or not :param track_drop: whether to register drop event of this record or not
f9835:c4:m0
def track_wait(self):
return self.__track_wait<EOL>
Return True if this task is tracking "postponing" event otherwise - False :return: bool
f9835:c4:m1
def track_drop(self):
return self.__track_drop<EOL>
Return True if this task is tracking "drop" event otherwise - False :return: bool
f9835:c4:m2
def task_postponed(self):
tracker = self.task().tracker_storage()<EOL>if tracker is not None and self.track_wait() is True:<EOL><INDENT>details = self.task().event_details(WTrackerEvents.wait)<EOL>tracker.register_wait(self.task(), event_details=details)<EOL><DEDENT>WScheduleRecord.task_postponed(self)<EOL>
Track (if required) postponing event and do the same job as :meth:`.WScheduleRecord.task_postponed` method do :return: None
f9835:c4:m3
def task_dropped(self):
tracker = self.task().tracker_storage()<EOL>if tracker is not None and self.track_drop() is True:<EOL><INDENT>details = self.task().event_details(WTrackerEvents.drop)<EOL>tracker.register_drop(self.task(), event_details=details)<EOL><DEDENT>WScheduleRecord.task_dropped(self)<EOL>
Track (if required) drop event and do the same job as :meth:`.WScheduleRecord.task_dropped` method do :return: None
f9835:c4:m4
@classmethod<EOL><INDENT>@verify_type('<STR_LIT>', record=WScheduleRecord)<EOL>def create(cls, record, registry):<DEDENT>
return cls(record, registry)<EOL>
Core method for watchdog creation. Derived classes may redefine this method in order to change watchdog creation process :param record: schedule record that is ready to be executed :param registry: registry that is created this watchdog and registry that must be notified of \ scheduled task stopping :return:
f9836:c0:m0
@verify_type(record=WScheduleRecord)<EOL><INDENT>def __init__(self, record, registry):<DEDENT>
WCriticalResource.__init__(self)<EOL>WPollingThreadTask.__init__(self, thread_name=self.__thread_name_prefix__ + str(record.task_uid()))<EOL>if isinstance(registry, WRunningRecordRegistry) is False:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>self.__record = record<EOL>self.__registry = registry<EOL>self.__task = None<EOL>
Create new watch dog. :param record: schedule record that is ready to be executed :param registry: registry that is created this watch dog and registry that must be notified of \ scheduled task stopping note: :class:`.WRunningRecordRegistry` is using :meth:`.WSchedulerWatchdog.create` method for watch dog creation
f9836:c0:m1
def record(self):
return self.__record<EOL>
Return scheduler record :return: WScheduleRecord
f9836:c0:m2
def registry(self):
return self.__registry<EOL>
Return parent registry :return: WRunningRecordRegistry
f9836:c0:m3
def start(self):
self.__dog_started()<EOL>WPollingThreadTask.start(self)<EOL>
Start scheduled task and start watching :return: None
f9836:c0:m4
def thread_started(self):
self.__thread_started()<EOL>WPollingThreadTask.thread_started(self)<EOL>
Start watchdog thread function :return: None
f9836:c0:m5
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>def __dog_started(self):<DEDENT>
if self.__task is not None:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>self.__task = self.record().task()<EOL>if isinstance(self.__task, WScheduleTask) is False:<EOL><INDENT>task_class = self.__task.__class__.__qualname__<EOL>raise RuntimeError('<STR_LIT>' % task_class)<EOL><DEDENT>
Prepare watchdog for scheduled task starting :return: None
f9836:c0:m6
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>def __thread_started(self):<DEDENT>
if self.__task is None:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>self.__task.start()<EOL>self.__task.start_event().wait(self.__scheduled_task_startup_timeout__)<EOL>
Start a scheduled task :return: None
f9836:c0:m7
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>def _polling_iteration(self):<DEDENT>
if self.__task is None:<EOL><INDENT>self.ready_event().set()<EOL><DEDENT>elif self.__task.check_events() is True:<EOL><INDENT>self.ready_event().set()<EOL>self.registry().task_finished(self)<EOL><DEDENT>
Poll for scheduled task stop events :return: None
f9836:c0:m8
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>def thread_stopped(self):<DEDENT>
if self.__task is not None:<EOL><INDENT>if self.__task.stop_event().is_set() is False:<EOL><INDENT>self.__task.stop()<EOL><DEDENT>self.__task = None<EOL><DEDENT>
Stop scheduled task beacuse of watchdog stop :return: None
f9836:c0:m9
@verify_subclass(watchdog_cls=(WSchedulerWatchdog, None))<EOL><INDENT>@verify_type(thread_name_suffix=(str, None))<EOL>def __init__(self, watchdog_cls=None, thread_name_suffix=None):<DEDENT>
WCriticalResource.__init__(self)<EOL>WRunningRecordRegistryProto.__init__(self)<EOL>thread_name = self.__thread_name__<EOL>if thread_name_suffix is not None:<EOL><INDENT>thread_name += thread_name_suffix<EOL><DEDENT>WPollingThreadTask.__init__(self, thread_name=thread_name)<EOL>self.__running_registry = []<EOL>self.__done_registry = []<EOL>self.__cleanup_event = Event()<EOL>self.__watchdog_cls = watchdog_cls if watchdog_cls is not None else WSchedulerWatchdog<EOL>
Create new registry :param watchdog_cls: watchdog that should be used (:class:`.WSchedulerWatchdog` by default) :param thread_name_suffix: suffix to thread name
f9836:c1:m0
def cleanup_event(self):
return self.__cleanup_event<EOL>
Return "cleanup" event :return: Event
f9836:c1:m1
def watchdog_class(self):
return self.__watchdog_cls<EOL>
Return watchdog class that is used by this registry :return: WSchedulerWatchdog class or subclass
f9836:c1:m2
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>@verify_type('<STR_LIT>', record=WScheduleRecord)<EOL>def exec(self, record):<DEDENT>
watchdog_cls = self.watchdog_class()<EOL>watchdog = watchdog_cls.create(record, self)<EOL>watchdog.start()<EOL>watchdog.start_event().wait(self.__watchdog_startup_timeout__)<EOL>self.__running_registry.append(watchdog)<EOL>
Start the given schedule record (no time checks are made by this method, task will be started as is) :param record: schedule record to start :return: None
f9836:c1:m3
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>def running_records(self):<DEDENT>
return tuple([x.record() for x in self.__running_registry])<EOL>
Return schedule records that are running at the moment :return: tuple of WScheduleRecord
f9836:c1:m4
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>def __len__(self):<DEDENT>
return len(self.__running_registry)<EOL>
Return number of running records :return: int
f9836:c1:m5
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>@verify_type(watchdog=WSchedulerWatchdog)<EOL>def task_finished(self, watchdog):<DEDENT>
if watchdog in self.__running_registry: <EOL><INDENT>self.__running_registry.remove(watchdog)<EOL>self.__done_registry.append(watchdog)<EOL>self.cleanup_event().set()<EOL><DEDENT>
Handle/process scheduled task stop :param watchdog: watchdog of task that was stopped :return: None
f9836:c1:m6
def _polling_iteration(self):
if self.cleanup_event().is_set() is True:<EOL><INDENT>self.cleanup()<EOL><DEDENT>
Poll for cleanup event :return: None
f9836:c1:m7
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>def cleanup(self):<DEDENT>
for task in self.__done_registry:<EOL><INDENT>task.stop()<EOL><DEDENT>self.__done_registry.clear()<EOL>self.cleanup_event().clear()<EOL>
Do cleanup (stop and remove watchdogs that are no longer needed) :return: None
f9836:c1:m8
def thread_stopped(self):
self.cleanup()<EOL>self.stop_running_tasks()<EOL>
Handle registry stop :return: None
f9836:c1:m9
@WCriticalResource.critical_section(timeout=__lock_acquiring_timeout__)<EOL><INDENT>def stop_running_tasks(self):<DEDENT>
for task in self.__running_registry:<EOL><INDENT>task.stop()<EOL><DEDENT>self.__running_registry.clear()<EOL>
Terminate all the running tasks :return: None
f9836:c1:m10
@verify_type(maximum_records=(int, None))<EOL><INDENT>@verify_value(maximum_records=lambda x: x is None or x >= <NUM_LIT:0>)<EOL>def __init__(self, maximum_records=None):<DEDENT>
self.__records = []<EOL>self.__maximum_records = maximum_records<EOL>
Create new registry :param maximum_records: maximum number of tasks to postpone (no limit by default)
f9836:c2:m0
def maximum_records(self):
return self.__maximum_records<EOL>
Return maximum number of records to postpone :return: int
f9836:c2:m1
@verify_type(record=WScheduleRecord)<EOL><INDENT>def postpone(self, record):<DEDENT>
maximum_records = self.maximum_records()<EOL>if maximum_records is not None and len(self.__records) >= maximum_records:<EOL><INDENT>record.task_dropped()<EOL>return<EOL><DEDENT>task_policy = record.policy()<EOL>task_group_id = record.task_group_id()<EOL>if task_policy == WScheduleRecord.PostponePolicy.wait:<EOL><INDENT>self.__postpone_record(record)<EOL><DEDENT>elif task_policy == WScheduleRecord.PostponePolicy.drop:<EOL><INDENT>record.task_dropped()<EOL><DEDENT>elif task_policy == WScheduleRecord.PostponePolicy.postpone_first:<EOL><INDENT>if task_group_id is None:<EOL><INDENT>self.__postpone_record(record)<EOL><DEDENT>else:<EOL><INDENT>record_found = None<EOL>for previous_scheduled_record, task_index in self.__search_record(task_group_id):<EOL><INDENT>if previous_scheduled_record.policy() != task_policy:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>record_found = previous_scheduled_record<EOL>break<EOL><DEDENT>if record_found is not None:<EOL><INDENT>record.task_dropped()<EOL><DEDENT>else:<EOL><INDENT>self.__postpone_record(record)<EOL><DEDENT><DEDENT><DEDENT>elif task_policy == WScheduleRecord.PostponePolicy.postpone_last:<EOL><INDENT>if task_group_id is None:<EOL><INDENT>self.__postpone_record(record)<EOL><DEDENT>else:<EOL><INDENT>record_found = None<EOL>for previous_scheduled_record, task_index in self.__search_record(task_group_id):<EOL><INDENT>if previous_scheduled_record.policy() != task_policy:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>record_found = task_index<EOL>break<EOL><DEDENT>if record_found is not None:<EOL><INDENT>self.__records.pop(record_found).task_dropped()<EOL><DEDENT>self.__postpone_record(record)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>
Postpone (if required) the given task. The real action is depended on task postpone policy :param record: record to postpone :return: None
f9836:c2:m2
@verify_type(task_group_id=str)<EOL><INDENT>def __search_record(self, task_group_id):<DEDENT>
for i in range(len(self.__records)):<EOL><INDENT>record = self.__records[i]<EOL>if record.task_group_id() == task_group_id:<EOL><INDENT>yield record, i<EOL><DEDENT><DEDENT>
Search (iterate over) for tasks with the given task id :param task_group_id: target id :return: None
f9836:c2:m3
@verify_type(record=WScheduleRecord)<EOL><INDENT>def __postpone_record(self, record):<DEDENT>
self.__records.append(record)<EOL>record.task_postponed()<EOL>
Save the record and trigger 'postpone' method :param record: record to save :return: None
f9836:c2:m4
def has_records(self):
return len(self.__records) > <NUM_LIT:0><EOL>
Check if there are postponed records. True - there is at least one postpone record, False - otherwise :return: bool
f9836:c2:m5