Skip to content
Snippets Groups Projects
Commit 27918286 authored by Sergey Esenov's avatar Sergey Esenov
Browse files

Fix bugs and improve wording

parent 7b39600e
1 merge request!6Periodic tasks in python bound
......@@ -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 "Threading" module
Usage of "threading" 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment