NICOS daemon package.
Bases: nicos.core.device.Device
Bases: Device
This class abstracts the main daemon process.
Parameters
Authentication method. Default value: 'none'.
Maximum number of logins. Default value: 10.
User/password list for authmethod “list”. Default value: [].
Whether to set SO_REUSEADDR. Default value: True.
Address to bind to (host or host:port).
Trusted hosts allowed to log in. Default value: [].
Update interval for watch expressions. Default value: 0.20000000000000001. Unit: s.
Parameters inherited from the base classes: description, loglevel, lowlevel
Bases: SocketServer.TCPServer
Bases: TCPServer
Last chance exception handling.
Process a “request”, that is, a client connection.
Thread to process the client connection, calls the Handler.
Give each handler a unique ID.
Close the server and its socket.
Remove a handler from the handlers dictionary.
Called on a new connection. If we have a connection from that host that lacks an event connection, use this.
The base class for communication with the NICOS server.
Bases: exceptions.Exception
Bases: Exception
Bases: object
Bases: exceptions.Exception
Bases: Exception
The connection handler for the execution daemon, handling the protocol commands.
Bases: exceptions.Exception
Bases: Exception
Raised to unconditionally close the connection.
Bases: SocketServer.BaseRequestHandler
Bases: BaseRequestHandler
This class is the SocketServer “request handler” implementation for the licos server. One instance of this class is created for every control connection (not event connections) from a client. When the event connection is opened, the event_sender method of the existing instance is spawned as a new thread.
The handle method reads commands from the client, dispatches them to methods of the same name, and writes the responses back.
Command methods must be decorated with the @command decorator; it registers the command for dispatching and avoids boilerplate: if the needcontrol argument is True, the command will need to be called in the controlling session. If the needscript argument is True or False, the command can only be called if a script is running or not running, respectively.
Note that the SocketServer interface is such that the request handling is done while the constructor runs, i.e. the __init__ method calls handle.
Check if the current thread is the session’s controlling thread.
Match the connecting host against the daemon’s trusted hosts list.
Take events from the handler instance’s event queue and send them to the client using the event connection.
Handle a single connection.
Read a command and arguments from the client.
Write a message to the client.
Decorates a nicosd protocol command. The needcontrol and needscript parameters can be set to avoid boilerplate in the handler functions.
Python interface to the _pyctl module, to control the execution of Python code via a C trace function.
Bases: _pyctl.Controller
Bases: Controller
The Controller object allows to execute Python code in a controlled environment using the Python tracing mechanism (using a C trace function instead of a Python one for speed).
The running code can therefore be halted and stopped from another thread. Additionally, the currently executed line and Python frame can be observed.
Halting works by calling a custom function (“break function”) from the trace function – until this function returns the execution is halted.
Stopping works by throwing an exception from the trace function into the frame executing code, where it should be allowed to propagate to the toplevel and exit excecution. The exception (ControlStop) inherits from BaseException. This works nicely together with “finally:” clauses, but requires that bare “except:” clauses are replaced by “except Exception:”.
There are various options to control breaking behavior. By default, a break can occur everywhere. “break_only_in_toplevel” limits breaking so that a break can only occur between two lines of code in the toplevel code. “break_only_in_filename” works similar, but if it is set, breaks can occur in all frames whose code has the given filename. Using this, breakpoints in non-toplevel code are implemented.
Using an “observer” callable, changes in the line number and execution need not be polled: each time the status or line number changes, the observer is called as observer(status, lineno).
The external interface is usually used like this:
In the executing thread: * instantiate the Controller object * call set_observer() to add an observer * call start()/start_exec()
In the controlling thread: * when halting is wanted, call set_break() * when continuing is wanted, call set_continue() * when stopping is wanted, call set_stop()
Signature of the C class:
Methods of the C class:
Attributes of the C class:
Return a stacktrace of the currently executed code.
Allow continuation of a halted execution.
Called from outside: stop execution.
Called from the break func: wait for set_continue() to be called.
Thread that executes user scripts.
Bases: nicos.daemon.script.Request
Bases: Request
An emergency stop request (while no script is running).
Bases: nicos.daemon.pyctl.Controller
Bases: Controller
The Controller object has two functions: it holds the state of the script thread, and it controls execution of scripts via a C trace function.
The script_thread_entry method is called in a separate thread, which then processes the requests put into self.queue by the server thread.
When set_break is called, execution is suspended and _breakfunc is called which waits until somebody calls set_continue or set_stop. Since break_only_in_filename is given at creation time, a break request will only break when the execution frame is one from the toplevel script.
The attributes currentframe and lineno correspond to the current execution frame and the current line number in the toplevel script.
See the docstring of pyctl.Controller for more details on the inner working of the Controller object and the trace function.
The script execution thread entry point. This thread executes setup code, then waits for scripts on self.queue. The script is then executed in the context of self.namespace, using the controller (self) to watch execution.
Bases: object
Abstract Request class.
The server communicates with the script thread via Requests. Each request is put onto a queue, which the script thread processes sequentially. A request can be for script execution, but also for termination of the script thread. Each request has a number, by which pending requests can be identified and ignored.
Bases: exceptions.Exception
Bases: Exception
Exception raised if a request cannot be queued.
Bases: exceptions.Exception
Bases: Exception
Exception raised if a script operation cannot be executed.
Bases: nicos.daemon.script.Request
Bases: Request
A request to execute a Python script.
This class holds the script to execute as well, and has all operations that can be done with the script: execute it, and update it.
Execute the script in the given namespace, using “controller” to execute individual blocks.
Update the code with a new script.
This method is called from a different thread than execute(), so we must unset the _run flag before doing anything to self.curblock, self.code or self.blocks.
Bases: nicos.daemon.script.Request
Bases: Request
A script thread termination request.
NICOS daemon user abstraction.
Bases: exceptions.Exception
Bases: Exception
Bases: object
Bases: object
Utilities for the NICOS daemon.
Bases: logging.Handler
Bases: Handler
Log handler for transmitting NICOS log messages to the client.
Bases: object
Adds more information to logging records. Similar to LoggerAdapter, which is new in Python 2.5.
Bases: threading.Thread
Bases: Thread
Thread for receiving messages from a pipe and sending them to the client.
Bases: logging.Handler
Bases: Handler
Log handler sending messages to the original daemon via a pipe.
Perform some fixup operations on the script.
Format an exception with traceback, but leave out the first cut number of frames.
Format a script with timestamp.
Print a timestamp to stdout.
Serialize an object.
Set the linecache for a pseudo-module so that the traceback module can extract the source code when creating tracebacks.