pcvs.backend.session module

class pcvs.backend.session.Session(date=None, path='.')[source]

Bases: object

Object representing a running validation (detached or not).

Despite the fact it is designed for manage concurrent runs, it takes a callback and can be derived for other needs.

Parameters:
  • _func (Callable) – user function to be called once the session starts

  • _sid (int) – session id, automatically generated

  • _session_infos (dict) – session infos dict

class State(value)[source]

Bases: IntEnum

Enum of possible Session states.

COMPLETED = 2
ERROR = 3
IN_PROGRESS = 1
WAITING = 0
classmethod from_yaml(constructor, node)[source]

Construct a Session.State from its YAML representation.

Relies on the fact the node contains a ‘Session.State’ tag. :param loader: the YAML loader :type loader: yaml.FullLoader :type node: :param node: the YAML representation :type node: Any :return: The session State as an object :rtype: Session.State

classmethod to_yaml(representer, data)[source]

Convert a Test.State to a valid YAML representation.

A new tag is created: ‘Session.State’ as a scalar (str). :param dumper: the YAML dumper object :type dumper: YAML().dumper :type data: :param data: the object to represent :type data: class:Session.State :return: the YAML representation :rtype: Any

property id

Getter to session id.

Returns:

session id

Return type:

int

property infos

Getter to session infos.

Returns:

session infos

Return type:

dict

load_from(sid, data)[source]

Update the current object with session infos read from global file.

Parameters:
  • sid (int) – session id read from file

  • data (dict) – session infos read from file

property(kw)[source]

Access specific data from the session stored info session.yml.

Parameters:

kw (str) – the information to retrieve. kw must be a valid key

Returns:

the requested session infos if exist

Return type:

Any

property rc

Gett to final RC.

Returns:

rc

Return type:

int

register_callback(callback)[source]

Register the callback used as main function once the session is started.

Parameters:

callback (Callable) – function to invoke

run(*args, **kwargs)[source]

Run the session normally, without detaching the focus.

Arguments are user function ones. This function is also in charge of redirecting I/O properly (stdout, file, logs)

Parameters:

args (tuple) – user function positional arguments

:param kwargs user function keyword-based arguments. :type kwargs: tuple

run_detached(*args, **kwargs)[source]

Run the session is detached mode.

Arguments are for user function only. :type args: :param args: user function positional arguments :type args: tuple :param kwargs user function keyword-based arguments. :type kwargs: tuple

Returns:

the Session id created for this run.

Return type:

int

property state

Getter to session status.

Returns:

session status

Return type:

int

pcvs.backend.session.list_alive_sessions()[source]

Load and return the complete dict from session.yml file

Returns:

the session dict

Return type:

dict

pcvs.backend.session.lock_session_file(timeout=None)[source]

Acquire the lockfil before manipulating the session.yml file.

This ensure safety between multiple PCVS instances. Be sure to call unlock_session_file() once completed

Parameters:

timeout (int) – return from blocking once timeout is expired (raising TimeoutError)

pcvs.backend.session.main_detached_session(sid, user_func, *args, **kwargs)[source]

Main function processed when running in detached mode.

This function is called by Session.run_detached() and is launched from cloned process (same global env, new main function).

Raises:

Exception – any error occuring during the main process is re-raised.

Parameters:
  • sid – the session id

  • user_func – the Python function used as the new main()

  • args (tuple) – user_func() arguments

  • kwargs (dict) – user_func() arguments

pcvs.backend.session.remove_session_from_file(sid)[source]

clear a session from logs.

Parameters:

sid (int) – the session id to remove.

pcvs.backend.session.store_session_to_file(c)[source]

Save a new session into the session file (in HOME dir).

Parameters:

c (dict) – session infos to store

Returns:

the sid associated to new create session id.

Return type:

int

pcvs.backend.session.unlock_session_file()[source]

Release the lock after manipulating the session.yml file.

The call won’t fail if the lockfile is not taken before unlocking.

pcvs.backend.session.update_session_from_file(sid, update)[source]

Update data from a running session from the global file.

This only add/replace keys present in argument dict. Other keys remain.

Parameters:
  • sid (int) – the session id

  • update – the keys to update. If already existing, content is replaced

Type:

dict