Server

class Server(cores=None, version=None, port=None, timeout=60)[source]

Manages a Comsol server instance.

Instances of this class start and eventually stop Comsol servers running on the local machine. Clients, either running on the same machine or elsewhere on the network, can then connect to the server at the port it exposes for that purpose.

Example:

import mph
server = mph.Server(cores=1)
print(f'Server listing on port {server.port}.')
server.stop()

The number of processor cores the server makes use of may be restricted. If no number is given, all cores are used by default.

A specific version of the Comsol back-end can be specified if several are installed on the machine, for example version='5.3a'. Otherwise the latest version is used.

The server can be instructed to use a given network port. If omitted, the first server started on the machine will use port 2036, servers started subsequently will use port numbers of increasing value. The actual port number of a server instance can be accessed via its port attribute once it has started.

A timeout can be set for the server start-up. The default is 60 seconds. TimeoutError is raised if the server failed to start within that period.

running()[source]

Returns whether the server process is still running.

stop(timeout=10)[source]

Shuts down the server.