Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
HowToBound
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Karabo
HowToBound
Commits
27918286
Commit
27918286
authored
5 years ago
by
Sergey Esenov
Browse files
Options
Downloads
Patches
Plain Diff
Fix bugs and improve wording
parent
7b39600e
Loading
Loading
1 merge request
!6
Periodic tasks in python bound
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/intro.rst
+20
-15
20 additions, 15 deletions
source/intro.rst
with
20 additions
and
15 deletions
source/intro.rst
+
20
−
15
View file @
27918286
...
...
@@ -355,23 +355,29 @@ by the user, for example:
self.counter += 1
self.log.INFO("*** periodicAction : counter = " + str(self.counter))
The worker can then be stopped like this:
The worker can then be stopped by overriding ``preDestruction`` method,
like this:
.. code-block:: python
if self.worker is not None:
if self.worker.is_running():
self.worker.stop()
self.worker.join()
self.worker = None
def preDestruction(self):
if self.worker is not None:
if self.worker.is_running():
self.worker.stop()
self.worker.join()
self.worker = None
This method will be automatically called during device shutdown process.
Usage of "
T
hreading" module
Usage of "
t
hreading" module
===========================
Sometimes it is simplier to use multithreading directly for executing
periodic tasks in python karabo device ``Klass``. First import
``threading`` module.
Sometimes if you would decide to use multithreading directly for executing
periodic tasks in python karabo device like ``Klass`` you may follow these
steps.
First import ``threading`` module.
.. code-block:: python
...
...
@@ -388,6 +394,7 @@ Then define class function that will do periodic work as a thread
.. code-block:: python
def polling(self):
self.running = True
while self.running:
# do some useful work like
# polling the hardware ...
...
...
@@ -401,7 +408,6 @@ Then define method that starts ``polling`` thread ...
def start_polling(self):
# use state here that fits your needs
self.updateState(State.MONITORING)
self.running = True
if self.pollingThread is None:
self.pollingThread threading.Thread(target=self.polling)
self.log.INFO("Start polling thread")
...
...
@@ -411,10 +417,9 @@ The ``start_polling`` may be placed into ``initialize`` function, into
slot of ``start`` button or another function that should activate
the periodic task.
Attention! If this device is killed the ``slotKillDevice`` is called,
which calls ``preDestruction`` method in turn. so it is important to
re-implement ``preDestruction`` method in ``Klass`` class to stop
running our polling loop above
If this device is killed the ``slotKillDevice`` is called,
which calls ``preDestruction`` method. So it is important to
override this method to stop running our polling loop above
.. code-block:: python
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment