Remote control

class brian.RemoteControlServer(server=None, authkey='brian', clock=None, global_ns=None, local_ns=None, level=0)

Allows remote control (via IP) of a running Brian script

Initialisation arguments:

server
The IP server details, a pair (host, port). If you want to allow control only on the one machine (for example, by an IPython shell), leave this as None (which defaults to host=’localhost’, port=2719). To allow remote control, use (‘’, portnumber).
authkey
The authentication key to allow access, change it from ‘brian’ if you are allowing access from outside (otherwise you allow others to run arbitrary code on your machine).
clock
The clock specifying how often to poll for incoming commands.
global_ns, local_ns, level
Namespaces in which incoming commands will be executed or evaluated, if you leave them blank it will be the local and global namespace of the frame from which this function was called (if level=1, or from a higher level if you specify a different level here).

Once this object has been created, use a RemoteControlClient to issue commands.

Example usage

Main simulation code includes a line like this:

server = RemoteControlServer()

In an IPython shell you can do something like this:

client = RemoteControlClient()
spikes = client.evaluate('M.spikes')
i, t = zip(*spikes)
plot(t, i, '.')
client.execute('stop()')
class brian.RemoteControlClient(server=None, authkey='brian')

Used to remotely control (via IP) a running Brian script

Initialisation arguments:

server
The IP server details, a pair (host, port). If you want to allow control only on the one machine (for example, by an IPython shell), leave this as None (which defaults to host=’localhost’, port=2719). To allow remote control, use (‘’, portnumber).
authkey
The authentication key to allow access, change it from ‘brian’ if you are allowing access from outside (otherwise you allow others to run arbitrary code on your machine).

Use a RemoteControlServer on the simulation you want to control.

Has the following methods:

execute(code)

Executes the specified code in the server process. If it raises an exception, the server process will catch it and reraise it in the client process.

evaluate(code)

Evaluate the code in the server process and return the result. If it raises an exception, the server process will catch it and reraise it in the client process.

set(name, value)

Sets the variable name (a string) to the given value (can be an array, etc.). Note that the variable is set in the local namespace, not the global one, and so this cannot be used to modify global namespace variables. To do that, set a local namespace variable and then call execute() with an instruction to change the global namespace variable.

pause()

Temporarily stop the simulation in the server process, continue simulation with the :meth:’go’ method.

go()

Continue a simulation that was paused.

stop()

Stop a simulation, equivalent to execute('stop()').

Example usage

Main simulation code includes a line like this:

server = RemoteControlServer()

In an IPython shell you can do something like this:

client = RemoteControlClient()
spikes = client.evaluate('M.spikes')
i, t = zip(*spikes)
plot(t, i, '.')
client.execute('stop()')