sessions Package

sessions Package

Contains the NICOS session classes, which contain all low-level global state of the NICOS runtime.

Only for internal usage by functions and methods.

class nicos.sessions.Session(appname)

Bases: object

The Session class provides all low-level routines needed for NICOS operations and keeps the global state: devices, configuration, loggers.

Within one NICOS process, there is only one singleton session object that is always importable using

from nicos import session

There are several specialized subclasses of Session; one of them will always be used in concrete applications.

action(what)
addLogHandler(handler)

Add a new logging handler to the list of handlers for all NICOS loggers.

beginActionScope(what)
breakpoint(level)

Allow breaking or stopping the script at a well-defined time.

level can be 1 to indicate a breakpoint “after current scan” or 2 to indicate a breakpoint “after current step”.

cache_class

alias of CacheClient

checkAccess(required)

Check if the current user fulfills the requirements given in the required dictionary. Raise AccessError if check failed.

This is called by the requires decorator.

clearExperiment()

Reset experiment-specific data.

commandHandler(command, compiler)

This method is called when the user executes a simple command. It should return a compiled code object that is then executed instead of the command.

class config

Bases: object

Singleton for settings potentially overwritten later.

Session.createDevice(devname, recreate=False, explicit=False)

Create device given by a device name.

If device exists and recreate is true, destroy and create it again. If explicit is true, the device is added to the list of “explicitly created devices”.

Session.createRootLogger(prefix='nicos')
Session.destroyDevice(devname)

Shutdown a device and remove it from the list of created devices.

Session.elog_event(eventtype, data)
Session.endActionScope()
Session.endMultiCreate()

Mark the end of a multi-create.

Session.export(name, obj)

Export an object obj into the NICOS namespace with given name.

Session.getDevice(dev, cls=None)

Return a device dev from the current setup.

If dev is a string, the corresponding device will be looked up or created, if necessary.

cls gives a class, or tuple of classes, that dev needs to be an instance of.

Session.getExportedObjects()

Return an iterable of all objects exported to the NICOS namespace.

Session.getLogger(name)

Return a new NICOS logger for the specified device name.

Session.getSetupInfo()

Return information about all existing setups.

This is a dictionary mapping setup name to another dictionary. The keys of that dictionary are those present in the setup files: ‘description’, ‘group’, ‘sysconfig’, ‘includes’, ‘excludes’, ‘modules’, ‘devices’, ‘startupcode’, ‘extended’.

Session.getSetupPath()

Return the current setup path.

Session.handleInitialSetup(setup, simulate)

Determine which setup to load, and try to become master.

Called by sessions during startup.

Session.loadSetup(setupnames, allow_special=False, raise_failed=False, autocreate_devices=None)

Load one or more setup modules given in setupnames and set up devices accordingly.

If allow_special is true, special setups (with group “special”) are allowed, otherwise ConfigurationError is raised. If raise_failed is true, errors when creating devices are re-raised (otherwise, they are reported as warnings).

Session.logUnhandledException(exc_info=None, cut_frames=0, msg='')

Log an unhandled exception (occurred during user scripts).

The exception is logged using the originating device’s logger, if that information is available.

Session.mode

The current execution mode of the session.

Session.notify(subject, body, what=None, short=None, important=True)

Send a notification unconditionally.

Session.notifyConditionally(runtime, subject, body, what=None, short=None, important=True)

Send a notification if the current runtime exceeds the configured minimum runtimer for notifications.

Session.readSetups()

Read information of all existing setups, and validate them.

Setup modules are looked for in the directory given by the “setups_path” entry in nicos.conf, or by “control_path”/setups.

Session.setMode(mode)

Set a new mode for the session.

This raises ModeError if the new mode cannot be switched to at the moment (for example, if switching to master mode, but another master is already active).

Session.setNamespace(ns)

Set the namespace to export commands and devices into.

Session.setSetupPath(path)

Set the path to the setup files.

Normally, the setup path is given in nicos.conf and does not need to be set explicitly.

Session.shutdown()

Shut down the session: unload the setup and give up master mode.

Session.startMultiCreate()

Store devices that fail to create so that they are not tried again and again during one setup process.

Session.unexport(name, warn=True)

Unexport the object with name from the NICOS namespace.

Session.unloadSetup()

Unload the current setup.

This shuts down all created devices and clears the NICOS namespace.

Session.updateLiveData(tag, filename, dtype, nx, ny, nt, time, data)

Send new live data to clients.

The parameters are:

  • tag - a string describing the type of data that is sent. It is used by clients to determine if they can display this data.
  • filename - a string giving the filename of the data once measurement is finished. Can be empty.
  • dtype - a string describing the data array in numpy style, if it is in array format.
  • nx, ny, nt - three integers giving the dimensions of the data array, if it is in array format.
  • time - the current measurement time, for determining count rate.
  • data - the actual data as a byte string.

console Module

Session class for console interface.

class nicos.sessions.console.ConsoleSession(appname)

Bases: nicos.sessions.Session

Bases: Session

Subclass of Session that configures the logging system for interactive interpreter usage: it adds a console handler with colored output, and an exception hook that reports unhandled exceptions via the logging system.

breakpoint(level)
checkAccess(required)
console()

Run an interactive console, and exit after it is finished.

forkSimulation(code, wait=True)
immediateStop()
loadSetup(setupnames, allow_special=False, raise_failed=False)
resetPrompt()
classmethod run(setup='startup', simulate=False)
setMode(mode)
signalHandler(signum, frame)
class nicos.sessions.console.NicosInteractiveConsole(session, globals, locals)

Bases: code.InteractiveConsole

Bases: InteractiveConsole

This class provides a console similar to the standard Python interactive console, with the difference that input and output are logged to the NICOS logger and will therefore appear in the logfiles.

interact(banner=None)
raw_input(prompt)
runcode(codeobj, source=None)

Mostly copied from code.InteractiveInterpreter, but added the logging call for exceptions.

runsource(source, filename='<input>', symbol='single')

Mostly copied from code.InteractiveInterpreter, but added the logging call before runcode().

class nicos.sessions.console.NicosInteractiveStop

Bases: exceptions.BaseException

Bases: BaseException

This exception is raised when the user requests a stop.

daemon Module

Session class used with the NICOS daemon.

class nicos.sessions.daemon.DaemonSession(appname)

Bases: nicos.sessions.simple.NoninteractiveSession

Bases: NoninteractiveSession

Subclass of Session that configures the logging system for running under the execution daemon: it adds the special daemon handler and installs a standard output stream that logs stray output.

breakpoint(level)
cache_class

alias of DaemonCacheClient

checkAccess(required)
clearExperiment()
forkSimulation(code, wait=True)
updateLiveData(tag, filename, dtype, nx, ny, nt, time, data)

simple Module

Session classes for simple and noninteractive use.

class nicos.sessions.simple.NoninteractiveSession(appname)

Bases: nicos.sessions.Session

Bases: Session

Subclass of Session that configures the logging system for simple noninteractive usage.

classmethod run(appname, maindevname=None, setupname=None, pidfile=True, daemon=False, start_args=[])
class nicos.sessions.simple.ScriptSession(appname)

Bases: nicos.sessions.Session

Bases: Session

Subclass of Session that allows for batch execution of scripts.

classmethod run(setup, code)
class nicos.sessions.simple.SingleDeviceSession(appname)

Bases: nicos.sessions.simple.NoninteractiveSession

Bases: NoninteractiveSession

utils Module

Utilities for the session classes.

class nicos.sessions.utils.LoggingStdout(orig_stdout)

Bases: object

Standard output stream replacement that tees output to a logger.

flush()
write(text)
class nicos.sessions.utils.NicosCompleter(namespace=None)

Bases: rlcompleter.Completer

Bases: Completer

This is a Completer subclass that doesn’t show private attributes when completing attribute access.

attr_matches(text)
get_matches(text)
global_matches(text)
class nicos.sessions.utils.NicosNamespace

Bases: dict

Bases: dict

A dict subclass that has a list of identifiers that cannot be set, except using the setForbidden() method.

addForbidden(name)
removeForbidden(name)
setForbidden(name, value)
class nicos.sessions.utils.SimClock

Bases: object

Simulation clock.

reset()
tick(sec)
wait(time)
nicos.sessions.utils.guessCorrectCommand(source, attribute=False)

Try to guess the command that was meant by source.

Will do a fuzzy match in all usercommands in the top level namespace and tries to find attributes if attribute is true.

nicos.sessions.utils.makeSessionId()

Create a unique identifier for the current session.

nicos.sessions.utils.sessionInfo(id)

Return a string with information gathered from the session id.

web Module

Session used for the NICOS web interface.

class nicos.sessions.web.WebSession(appname)

Bases: nicos.sessions.Session

Bases: Session

Subclass of Session that configures the logging system for usage in a web application environment.

classmethod run(setup='startup')

Table Of Contents

Previous topic

monitor Package

Next topic

taco Package