class Server(cores=None, version=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.


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

For this to work, make sure the Comsol server was started at least once from the command line, so that you have had a chance to define a user name and password.

For client―server connections across the network, the server’s host name or IP address has to be known by the client up front. It has to be either hard-coded or managed otherwise. Though if client and server run on the same machine, it is simply "localhost". (However, in that situation, you may be better served — pardon the pun — to simply run a stand-alone client.)

The first server starting on a given computer will typically accept client connections on TCP communication port 2036, as per Comsol’s default configuration. 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 after it has started.

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.

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


Returns whether the server process is still running.


Shuts down the server.