state_machine_db¶
state_machine_db provides the implementation of a recoverable (sqlite3) state machine
Example¶
>>> import logging
>>> loggin.basicConfig()
>>> from state_machine_db import StateMachine
>>> st = StateMachine('/tmp/db.sqlite', 'first')
>>> st.logger.setLevel('DEBUG')
>>> st.start()
>>> st.update_flag = True
Installation¶
To install state_machine, simply run:
$ pip install state_machine_db
state_machine_db is compatible with Python 2.6+ and python 3
Documentation¶
Source Code¶
Feel free to fork, evaluate and contribute to this project.
License¶
GPLv3 licensed.
state_machine_db package contents:¶
state_machine_db package¶
Submodules¶
state_machine_db.state_machine module¶
This module implements a state machine that waits for flags to jump from state to state until it is finished
-
class
state_machine_db.state_machine.
StateMachine
(sm_database_path, activity_id)¶ Bases:
threading.Thread
Implements a totally configurable state machine
Parameters: - sm_database_path (
str
) – path to the sqlite database - activity_id (
str
) – identifier for the current state machine instance
-
static
check_if_thread_alive
(activity_id)¶ Checks if there is a thread related to activity_id
Parameters: activity_id ( str
) – identifier for the current state machine instanceReturns: True if there is a thread, False otherwise
-
static
get_sm_alive_threads
()¶ Get info about all running threads related to state machine
Returns: A dictionary containing the name of each running thread and its thread object
-
get_updated_states
()¶ This method must be implemented in the child class and return, after an update in the update_flag, a list of updated states
-
run
()¶ Initiates the thread that effectivelly implements the state machine. A change of state must be sinalized by a flag (update, must be True) The final state must be sinalized by a flag (is_finished, must be True)
- sm_database_path (