papi package

Subpackages

Submodules

papi.ConsoleLog module

Contributors: Stefan Ruppin

class papi.ConsoleLog.ConsoleLog(lvl, identifier)[source]

Bases: builtins.object

printText(l, msg)[source]

papi.constants module

Contributors Stefan Ruppin

papi.core module

Contributors Stefan Ruppin

class papi.core.Core(gui_start_function=None, use_gui=True, is_parent=True, gui_process_pid=None, args=None)[source]

Bases: builtins.object

__process_alive__(event)[source]

Processes alive response from processes/plugins and GUI, organising the counter, i.e. increment GUI counter if alive event’s origin is GUI, otherwise increment counter stored in dplugin object

Alive events that were sent by plugins are the response on alive request which were sent by the core alive timer. An alive event indicates that the plugin is still running and responding to requests.

Parameters:event (PapiEventBase) – event to process
__process_close_programm__(event)[source]

This functions processes a close_program event from GUI and sends events to all processes to close themselves

The GUI can request the close to quit PaPI.

The method will request all other processes to stop their execution and to close.

Parameters:event (PapiEventBase) – event to process
__process_create_plugin__(event)[source]

Processes create_plugin event. So it will create a plugin, start a process if needed, send events to GUI to create a plugin and do the pre configuration

This method reacts to the create plugin event. Such an event, is mostly sent by the GUI.

The method extracts all the necessary plugin properties from the event. Then, the yapsy plugin loader tries to find the plugin via its identifier. Afterwards, the PaPI dplugin object is created and filled with all information. It is decided if the plugin runs in the GUI or in an own process. Based on this, a new process is created or the plugin is redirected to the GUI process. The startup configurations are merged and passed to the plugin.

Parameters:
  • event (PapiEventBase) – event to process
  • optData (DOptionalData) – optional Data Object of event
Returns:

-1: Error

__process_data_event__(event)[source]

First stage of event processing, deciding which data_event this is

Parameters:event (PapiEventBase) – event to process
__process_delete_block__(event)[source]

Processes delete_block event.

The event is sent by a plugin if the plugin wants to delete one of its own blocks (plugin updates itself).

The methods searches in the dplugin object for the block and deletes it. Before deletion, all block subscriptions are cut loose to ensure that no dead links are created.

Parameters:event (PapiEventBase) – event to process
__process_delete_parameter__(event)[source]

Processes delete parameter event.

The event is sent by a plugin if the plugin wants to delete one of its own parameter (plugin updates itself).

The methods searches in the dplugin object for the parameter and deletes it. Before deletion, all parameter subscriptions are cut loose to ensure that no dead links are created.

Parameters:event (PapiEventBase) – event to process
Returns:
__process_edit_dplugin_by_uname__(event)[source]

This function processes edit plugin events and acts like a wrapper for the ‘__process_edit_dplugin’ function which requires plugin ids instead of unames.

Documentation of what the method does can be found in the method: __process_edit_dplugin

Parameters:event
Returns:
__process_event__(event)[source]

Initial stage of event processing, dividing by event type Extracts event type and give it to a switch case equivalent

Parameters:event (PapiEventBase) – event to process
__process_instr_event__(event)[source]

First stage of event processing, deciding which instr_event this is. Therefore, the method extracts the event operation and processes it.

Parameters:event (PapiEventBase) – event to process
__process_join_request__(event)[source]

Process join requests of processes

A join request is send from a plugin which will close itself. The requests wants the core to join the process of the plugin for clean-up reasons. Therefore, the join request is just send by plugins running in an own process (and not in the GUI).

The method is searching for the dplugin object in the core database to get the corresponding process object. Then, the method joins the process. Note, that a join request is the last action of a plugin to ensure that the core is not blocked by the process join procedure. Afterwards, the plugin will be removed from the core’s database. A event is send to the GUI process to inform the GUI about the closed and removed plugin.

Parameters:event (PapiEventBase) – event to process
__process_new_block__(event)[source]

Processes new_block event. Will try to add a new data block to a DPlugin object

This event is a request from a plugin to create a new block.

The method receives all block information via the event. It searches the corresponding pluign and add the blocks

Parameters:event (PapiEventBase) – event to process
__process_new_data__(event)[source]

Process new_data event from plugins. Will do the routing: Subscriber/Subscription

This method is doing all the magic in PaPI. It routes all data to its target and decides whether subscription are for data or parameters.

First, it is checked if the GUI is alive, since no data shall be processed if the GUI is already closed. Then, the dplugin object of the origin of the data event is searched. Then, the block of the new data is searched. With the block object of the origin plugin, the subscriber list can be extracted. Then, for every subscriber of the block (which has new data available), the plugin object is searched. If a subscriber plugin is running (not dead/stopped), the data event is routed to it. For subscriber running in the GUI, just one event is sent with multiple receipts. Data events which represent parameter subscriptions are handles separately.

Parameters:event (PapiEventBase) – event to process
__process_new_parameter__(event)[source]

Processes new parameter event. Adding a new parameter to DPluign in DCore and updating GUI information

Parameters:event (PapiEventBase) – event to process
__process_pause_plugin__(event)[source]

Processes pause_plugin event. Will add information that a plugin is paused and send event to plugin to pause it.

Pause events are request from the GUI to pause a plugin. Paused plugins will not execute its execution function and thus, lower the computational load.

Parameters:event (PapiEventBase) – event to process
__process_plugin_stopped__(event)[source]

Process plugin_stopped event. Will change plugins state and delete its parameters and blocks. Will update meta to gui

The event is the result of a stop request of a plugin. A plugin which is request to stop its operation (no deletion) sends the plugin stopped event to confirm that it has stopped its operation.

The method searches the plugin in the database and updates its state. Additionally, all subscribers, blocks and parameter are removed/delete.

Parameters:event (PapiEventBase) – Incomming event
Returns:
__process_resume_plugin__(event)[source]

Processes resume_plugin event. Will add information that a plugin is resumed and send event to plugin to resume it.

Resumes a paused plugin to make it work again. So, the plugin will execute its main functions again.

Parameters:event (PapiEventBase) – event to process
__process_set_parameter__(event)[source]

Process set_parameter event. Core will just route this event from GUI to destination plugin and update DCore

The set parameter event is sent from plugins to some plugins to trigger parameter changes.

First, the method checks whether the event is an event by uname or by id. When the event is by uname, it is modified to be by id. If the plugin which the event refers to is not started yet, the event is put in the delayed operation queue. Then, the correct dplugin object and an event by id is available. The dplugin object is searched for the parameter which is changed. If the parameter exists, its value in the database is changed and then, the change event is redirected to the plugin itself.

Parameters:event (PapiEventBase) – event to process
__process_start_failed__(event)[source]

Process start failed event and do error handling

This event occurs when a plugin returns false in its initialize routine. Therefore, it means that the start of failed but the plugin noticed it itself and was able to return false.

This method will update the core database with the new state of the plugin. At the moment, no other actions are done.

Parameters:event (PapiEventBase) – event to process
__process_start_plugin__(event)[source]

Processes start event for a plugin.

The start plugin event is a request for the core to send a start event to a plugin. The plugin will be started by receiving the event, i.e. it will call its initialize function and start its execution afterwards.

The methods searches the plugin in the database and checks wheter it has its own process or not. Then, it will send an event to the corresponding queue to tell the plugin it should start.

Parameters:event (PapiEventBase) – Incomming event
Returns:
__process_start_successfull__(event)[source]

Process start_successful event.

A start_successful event is sent by plugins after their initialize function returned ‘true’ indicating a successful start of the plugin before continuing with its main execution routine.

Parameters:event (PapiEventBase) – event to process
__process_status_event__(event)[source]

First stage of event processing, deciding which status_event this is. Therefore, the method extracts the event operation and processes it.

Parameters:event (PapiEventBase) – event to process
__process_stop_plugin__(event)[source]

Process stop_plugin event. Will send an event to destination plugin to close itself. Will lead to a join request of this plugin.

A stop plugin event is sent by the GUI to the core to request the core to stop a plugin. ‘Stop’ means that: either the plugin is just stopped and not deleted or the plugin execution is stopped and the is deleted from the database (i.e. it is cleaned). It is determines by a flag which of them is used.

The methods searches for the dplugin object in the core database. If the plugin runs in an own process, the stop event is redirected to the corresponding plugin (to notify it to close itself). The core will cut all subscriptions&subscribers loose and update the gui data with the new plugin state. If the plugin is not running in an own process (runs in GUI), the event is checked for the delete flag. If the delete flag is set, the method will send a close request to the plugin. If not, the plugin will receive a customized stop event. The state will be modified and updated to the GUI.

Parameters:event (PapiEventBase) – event to process
__process_stop_plugin_by_uname__(event)[source]

Just a wrapper function for ‘__process_stop_plugin__’ to use the uname instead of a plugin id.

Parameters:event
Returns:
__process_subscribe__(event)[source]

Process subscribe_event.

The event is sent to create new data connections between plugins.

The method will call the functional method ‘new_subscription’ will the necessary arguments, like SourceID, Block, Signals, Alias

Parameters:event (PapiEventBase) – event to process
__process_subscribe_by_uname__(event)[source]

Process subscribe_event. Uses uname instead of IDs

The event is sent to create new data connections between plugins.

The method will call the functional method ‘new_subscription’ will the necessary arguments, like SourceID, Block, Signals, Alias

Parameters:event (PapiEventBase) – event to process
__process_unsubsribe__(event)[source]

Process unsubscribe_event. Will try to remove a subscription from DCore

Parameters:event (PapiEventBase) – event to process
check_alive_callback()[source]

Callback function for check_alive status timer, get called every time the timer triggers, does sth and starts a new timer. Handles sending events to processes and checking their answer.

Returns:
check_events_in_delayed_queue()[source]

Process all events which are in the delayed operation queue by poping them out and inserting them to the main core event queue ‘core_event_queue’ :return:

gui_is_dead_error_handler()[source]

Error handler for the case that the gui is dead. The handler gets called by the method ‘handle_alive_situation’ in case the gui counter does not match

Returns:
handle_alive_situation()[source]

Function which handles the check for the alive situation of all plugins in data base Will distribute to error_handling methods to handle dead processes This is no callback functions, more a rather periodically called method to check the alive situation. Is called by the handler which handles the alive timer callbacks

It checks the counter of the plugins and compares them against the core counter. A not equal (normally smaller) number in the plugin object indicates a dead process. A error handler is called.

Returns:
handle_parameter_change(plugin, parameter_name, value)[source]

This function should be called whenever there is a new_data event for changing a parameter value This function changes the value in DCore and updates this information to the GUI via a meta update

Parameters:
  • plugin (DPlugin) – Plugin which owns the parameter
  • parameter_name (basestring) – Name of the parameter which value should be changed
  • value (all possible, depends on plugin) – new value for the parameter
Returns:

-1 for error(parameter with parameter_name does not exist in plugin), 1 for o.k., done

new_subscription(subscriber_id, source_id, block_name, signals, sub_alias, orginal_event=None)[source]

Gets information of a new and desired subscription. This method will try to create the wanted subscription.

Parameters:
  • subscriber_id – Id of the plugin that want to get data
  • source_id – Id of the plugin that will be the data source
  • block_name – name of source block of source plugin
  • signals – signals to subscribe
  • sub_alias – optional alias for parameter
Returns:

plugin_process_is_dead_error_handler(dplug)[source]

Error handler for the case that the a plugin is dead. The handler gets called by the method ‘handle_alive_situation’ in case the plugin counter does not match

Parameters:dplug (DPlugin) – Plugin which is dead
Returns:
run()[source]

Main operation function of core. Event loop is in here.

Returns:
send_alive_check_events()[source]

Function for check_alive_status timer to send check_alive events to all running processes This will trigger all correctly running processes to send an answer to core. Alive response is handled in method ‘__process_alive__’ :return:

signal_handler(signal, frame, core)[source]

Callback-handler for signal from cmd line like e.g. SIGINT :return:

update_meta_data_to_gui(pl_id, inform_subscriber=False)[source]

On call, this function sends the meta information of the plugin with pl_id to the GUI With meta information is meant: all data in the dplugin object which is not process related (e.g. ids, names, states, subscriptions) The methods should be called everywhere, where some of those information are changed and a update in other processes is required/wanted. Additionally, subscriber of the plugin ‘pl_id’ are informed/

The methods takes the dplugin specified by its id and extracts all the meta data. Then, sends the updated meta data to the gui. Afterwards, if required, the subscriber will be informed by calling this methods (some kind of recursive) again with another id.

Parameters:
  • pl_id (int) – id of plugin with new meta information
  • inform_subscriber (bool) – flag used to determine if a meta_update for all subscriber should be initiated
Returns:

update_meta_data_to_gui_for_all()[source]

This functions update the meta data of all plugins to the GUI process by iteration over the plugin database and calling ‘update_meta_data_to_gui’ for every plugin id. :return:

class papi.core.Process_dummy[source]

Bases: builtins.object

papi.core.run_core_in_own_process(gui_queue, core_queue, gui_id)[source]

papi.error_codes module

Contributors Stefan Ruppin

papi.exceptions module

Contributors: Stefan Ruppin Sven Knuth

exception papi.exceptions.WrongLength(parameter, isLen, shLen)[source]

Bases: builtins.Exception

exception papi.exceptions.WrongType(parameters, expected_type=None)[source]

Bases: builtins.Exception

papi.helper module

Contributors: <Stefan Ruppin

papi.helper.get_color_by_string(color_string, inverse=False)[source]

Module contents