The processes module

The processes module contains modules and classes pertaining to managing systems with multiple processes.

The coroutine function

pyamp.processes.coroutine(func)

Decorator to create a coroutine and call next on it.

  • function – The function to decorate

The Thread class

class pyamp.processes.Thread(conditionFn=<function <lambda> at 0xa37fa74>, logger=None)

The Thread class provides a base class for creating threaded classes. It is essentially a wrapper for the threading.Thread class to make threaded classes easier to manage.

It provides the following functions that can be overridden by subclasses:

  • onStart(self) – This function is called when the Thread is started.

  • onException(self, e, trace) – This function is called in the event that

    an exception is encountered while the Thread is cycling.

  • onCycle(self, increment) – This function is called once each time the

    Thread cycles.

  • onShutdown(self) – This function is called in the event that the Thread

    is shutdown.

Once the Thread has started it continues to run until the shutdown() function is called, or until the condition function returns False.

Subclasses can set the Period property which sets the number of seconds that the Thread will sleep at the end of each cycle. The default value is one millisecond.

This class implements the pyamp.logging.Loggable interface.

  • conditionFn – A function that determines when the Thread should exit
  • logger – The logger for this class
isRunning()

Determine if the Thread is still running.

onCycle(increment)

This method is called when at each cycle of the Thread and should be overridden by subclasses.

Note

This function should be overridden by concrete Threads.

  • increment – The current increment number
onException(e, trace)

The Thread encountered an exception.

Note

This function should be overridden by concrete Threads.

  • e – The exception
  • trace – The traceback for the exception
onShutdown()

This method is called when the Thread is shut down and should be overridden by subclasses.

Note

This function should be overridden by concrete Threads.

onStart()

This method is called when the Thread is started and should be overridden by subclasses.

Note

This function should be overridden by concrete Threads.

onStop()

This method is called when the Thread is stopped.

Note

This function should be overridden by concrete Threads.

run()

Run the Thread until it is shut down or its condition function returns False.

shutdown()

Shutdown the Thread.

The Cycle class

class pyamp.processes.Cycle(conditionFn, logger=None)

The Cycle class provides a class which will continue cycling until a condition is no longer True.

  • conditionFn – The condition function
  • logger – The logger object
shutdown()

Stop cycling.

start()

Start cycling until the condition function returns False.

Table Of Contents

This Page