Instance
- class rips.Instance(port: int = 50051, launched: bool = False, enable_heartbeat: bool = True)
Bases:
objectThe ResInsight Instance class. Use to launch or find existing ResInsight instances
- launched
Tells us whether the application was launched as a new process. If the application was launched we may need to close it when exiting the script.
- Type:
bool
- port
The port number used to connect to this instance.
- Type:
int
- commands
Command executor. Set when creating an instance.
- Type:
Commands
- project
Current project in ResInsight. Set when creating an instance and updated when opening/closing projects.
- Type:
Methods Summary
Raise
RipsErrorif the heartbeat has flagged a lost connection.Get a full version string, i.e. 2019.04.01.
exit()Tell ResInsight instance to quit
find([start_port, end_port, enable_heartbeat])Search for an existing Instance of ResInsight by testing ports.
Returns true if the connected ResInsight instance is a console app
is_gui()Returns true if the connected ResInsight instance is a GUI app
launch([resinsight_executable, console, ...])Launch a new Instance of ResInsight.
Get an integer with the major version number
Get an integer with the minor version number
Get an integer with the patch version number
set_export_folder(export_type, path[, ...])Set the export folder used for all export functions
set_main_window_size(width, height)Set the main window size in pixels
set_plot_window_size(width, height)Set the plot window size in pixels
set_start_dir(path)Set current start directory
start_heartbeat([interval_sec, ...])Start a background thread that periodically pings ResInsight.
Stop the background heartbeat thread, if running.
Get a full version string, i.e. 2019.04.01.
Methods Documentation
- check_alive() None
Raise
RipsErrorif the heartbeat has flagged a lost connection. Cheap to call before issuing API requests.
- client_version_string() str
Get a full version string, i.e. 2019.04.01
- exit()
Tell ResInsight instance to quit
- static find(start_port: int = 50051, end_port: int = 50071, enable_heartbeat: bool = True) Instance
Search for an existing Instance of ResInsight by testing ports.
By default we search from port 50051 to 50071 or if the environment variable RESINSIGHT_GRPC_PORT is set we search RESINSIGHT_GRPC_PORT to RESINSIGHT_GRPC_PORT+20
- Parameters:
start_port (int) -- start searching from this port
end_port (int) -- search up to but not including this port
enable_heartbeat (bool) -- If True (default), a background thread pings the server periodically and aborts pending RPCs if it dies. Disable on slow boxes where false positives matter (long GC pauses, debugger).
- is_console() bool
Returns true if the connected ResInsight instance is a console app
- is_gui() bool
Returns true if the connected ResInsight instance is a GUI app
- static launch(resinsight_executable: str = '', console: bool = False, launch_port: int = 0, init_timeout: int = 300, command_line_parameters: List[str] = [], enable_heartbeat: bool = True) Instance
Launch a new Instance of ResInsight. This requires the environment variable RESINSIGHT_EXECUTABLE to be set or the parameter resinsight_executable to be provided. The RESINSIGHT_GRPC_PORT environment variable can be set to an alternative port number.
- Parameters:
resinsight_executable (str) -- Path to a valid ResInsight executable. If set will take precedence over what is provided in the RESINSIGHT_EXECUTABLE environment variable.
console (bool) -- If True, launch as console application, without GUI.
launch_port (int) -- If 0, GRPC will find an available port. If -1, use the default port 50051 or RESINSIGHT_GRPC_PORT If anything else, ResInsight will try to launch with the specified portnumber.
init_timeout -- Number of seconds to wait for initialization before timing out.
command_line_parameters (list) -- Additional parameters as string entries in the list.
enable_heartbeat (bool) -- If True (default), a background thread pings the server periodically and aborts pending RPCs if it dies. Disable on slow boxes where false positives matter (long GC pauses, debugger).
- Returns:
a connected instance object. Raises
RipsErroron failure.- Return type:
- major_version() int
Get an integer with the major version number
- minor_version() int
Get an integer with the minor version number
- patch_version() int
Get an integer with the patch version number
- set_export_folder(export_type: str, path: str, create_folder: bool = False)
Set the export folder used for all export functions
Parameters:
Parameter | Description | Type ---------------- | -------------------------------------------- | ----- export_type | String specifying what to export | String path | Path to folder | String create_folder | Create folder if it doesn't exist? | Boolean
Enum export_type:
Option | Description --------------- | ------------ "COMPLETIONS" | "SNAPSHOTS" | "PROPERTIES" | "STATISTICS" |
- set_main_window_size(width: int, height: int)
Set the main window size in pixels
Parameters:
Parameter | Description | Type --------- | ---------------- | ----- width | Width in pixels | Integer height | Height in pixels | Integer
- set_plot_window_size(width: int, height: int)
Set the plot window size in pixels
Parameters:
Parameter | Description | Type --------- | ---------------- | ----- width | Width in pixels | Integer height | Height in pixels | Integer
- set_start_dir(path: str)
Set current start directory
- Parameters:
path (str) -- path to directory
- start_heartbeat(interval_sec: float = 5.0, deadline_sec: float = 5.0, failure_threshold: int = 3, on_failure: Callable[[RipsError], None] | None = None) None
Start a background thread that periodically pings ResInsight.
A single missed ping is not fatal: the heartbeat tolerates up to
failure_threshold - 1consecutive failures (e.g. transient slowness on a loaded CI box) before declaring the connection lost. A successful ping resets the counter.Once the threshold is reached, the instance is marked as
connection_lost, the underlying gRPC channel is closed so any in-flight calls fail fast withUNAVAILABLE, and the retry interceptor is told to stop retrying. Subsequent API calls that go throughcheck_alive()raiseRipsErrorwith the captured cause.Heartbeat is opt-in. Existing scripts are unaffected unless they call this method.
- Parameters:
interval_sec -- Seconds between pings.
deadline_sec -- Per-ping deadline. Pings exceeding this are treated as failures.
failure_threshold -- Number of consecutive failed pings required before the connection is declared lost. Must be >= 1.
on_failure -- Optional callback invoked once when the heartbeat detects a lost connection. Receives a
RipsError.
- stop_heartbeat() None
Stop the background heartbeat thread, if running.
- version_string() str
Get a full version string, i.e. 2019.04.01