22 Commits
Author SHA1 Message Date
Kristian Bendiksen e7608536cf #13982 Python: Tighten Instance.launch/find return type and drop dead None checks
Instance.launch and Instance.find now always either return a connected
Instance or raise RipsError, so their return type narrows from
Optional[Instance] to Instance. In launch(), the unreachable `if pid:`
guard around the Popen result and the trailing `return None` are
removed; the only failure paths raise RipsError.

Update the PythonExamples that previously branched on a None return:
- Drop `if resinsight is None: exit(1)` style guards and `if resinsight
  is not None:` wrappers; dedent the body where applicable.
- export_corner_point_grid.py used the None check as a fallback to
  launch ResInsight; rewrite as try/except rips.RipsError so the
  fallback still works.
- instance_example.py is repurposed as a try/except example for
  reporting connection failure.
2026-05-13 13:47:40 +02:00
Kristian Bendiksen 96dc4df316 #9336 Python: Tolerate transient heartbeat failures
The heartbeat introduced in db871296c closed the gRPC channel after a
single missed ping (2s deadline). On Windows CI under load this fired
during normal operations, leaving every subsequent test stuck on a
dead channel.

Track consecutive failures inside the heartbeat loop and only declare
the connection lost after failure_threshold (default 3) consecutive
failures. A successful ping resets the counter. Per-ping deadline
raised from 2s to 5s, and below-threshold failures log a warning so
transient slowness is still visible.
2026-05-04 20:03:39 +02:00
Kristian Bendiksen f8d180f48d #9336 Python: Improve error reporting from gRPC to client
Surface gRPC failure context to Python script authors instead of
silently returning sentinel values or raising bare gRPC errors.

- RipsError now carries code/details/location and a from_rpc_error()
  helper. Existing single-arg construction stays valid.
- Stop swallowing grpc.RpcError in case.__grid_count for non-NOT_FOUND
  failures and in instance._check_connection_and_version, so the
  underlying status is propagated.
- pdmobject add_method decorator and _call_pdm_method_* attach
  code/details to the raised RipsError; existing message text is
  preserved so pytest match=... assertions keep working.
- Instance.start_heartbeat / stop_heartbeat / check_alive provide an
  opt-in background ping that flips a sticky lost-connection flag and
  raises a readable RipsError from check_alive() if the server dies.
- Server side: GetPdmObject in RiaGrpcAppService, RiaGrpcCaseService
  and RiaGrpcProjectService no longer return Status::OK with an empty
  reply when the underlying object is missing; they return NOT_FOUND
  / INTERNAL with a descriptive message. Other RiaGrpc*Service files
  audited and already return non-OK with text on error paths.
2026-05-04 20:03:39 +02:00
Copilot 9701f695d8 Python: Expose port number in the Instance class 2026-03-23 08:59:52 +01:00
Kristian Bendiksen 75bc84e146 #12452 Python: Replace logger.error with raise RipsError in instance.py
Error conditions in launch() and find() now raise RipsError instead of
logging and returning None, making failures explicit. Updated test to
expect the exception.
2026-03-05 15:58:25 +01:00
Kristian Bendiksen e4ea6ea44f #12452 Python: Replace print() with logging API in rips module 2026-03-05 15:58:25 +01:00
Kristian Bendiksen 83eda0adcf Python: Replace os.spawnv with subprocess.Popen in Instance.launch
Use subprocess.Popen instead of os.spawnv to launch ResInsight, avoiding
fork() deprecation warnings in multi-threaded contexts with gRPC.
2026-02-09 08:27:23 +01:00
Kristian Bendiksen da923b5731 #10751 Fix os.kill() on Windows by using SIGTERM instead of CTRL_C_EVENT
Fixes #10751.
2026-02-04 15:00:02 +01:00
Magne Sjaastad 96f953b4ff #12958 Check if executable exists before trying to launch ResInsight 2025-10-01 08:10:03 +02:00
Kristian Bendiksen 7899736f05 Python ruff fixes
* Python: Clean up imports.
* Python: Clean up error handling example.
* Python: Remove unused local variables
* Python: Avoid comparing against True/False.
* Python: Remove unused name variable.
* Python: Reuse class definition type variable.
* Python: Fix more unused imports
* Black fixes
2025-05-16 15:46:45 +02:00
Kristian Bendiksen 93f856cc53 Python: increase launch timeout. 2024-09-05 09:06:21 +02:00
Magne Sjaastad b730a077f1 #11626 Python: By default, use port number assigned by GRPC
Using ResInsight in a server environment when many multiple versions of ResInsight is launched, can cause the port assignment to fail. Change the default value for launch_port from -1 to 0, as this will improve the logic used to assign a port to a new ResInsight session.

Using 0 will ask GRPC to find an available port to be used.
2024-08-21 09:29:18 +02:00
Magne Sjaastad 84a07eed2b #11463 Look for resinsight_executable in JSON
Search for resinsight_executable in JSON-file located at ./share/rips/rips_config.json
2024-06-05 14:33:07 +02:00
Magne Sjaastad 14faf607f4 Improve error message for ResInsight exe and rips version mismatch 2024-01-18 08:54:56 +01:00
Kristian Bendiksen 7aabe8c4a8 Python: add type hinting to python code.
Types are checked using mypy.

Fixes #10394.
2023-08-23 09:47:44 +02:00
Kristian Bendiksen d046e2692c Fix python kill signal (#9320)
* Python: Fix incorrect call to os.kill.

Also make it work on platforms without unix signals.

* Python: Increase process file timeout to one minute.
2022-09-29 07:37:31 +02:00
Kristian Bendiksen c2b5ab8d2c #9307 Python: avoid assigning same port number to multiple grpc sessions
* Python: avoid assigning same port number to multiple grpc sessions
* Add retry count when checking for port number file
* Use grpc to find and use port number
* Add test used to start several instances of resinsight at the same time
Testing up to 50 instances works well

* Python: allow launch_port == 0 to assign port by GRPC in Instance.launch().
Also allow longer wait before failing the port number file reading:
it can take some time to launch when launching lots of instances at
the same time.
2022-09-26 14:19:21 +02:00
Magne Sjaastad 3a94078867 Support optimized surface export from grid model layers
* #7885 Update opm-common with optimized coordinate import
* #7885 Allow null as default result from a script method
* #7885 Propagate default parameter values to generated Python code
* #7885 Add CommandRouter as hub for worker methods
* #7885 Add support for use of CommadRouter from Python
2021-08-23 11:58:32 +02:00
Kristian Bendiksen f799ee2f3d #7842 Python: fix undefined variable on version mismatch.
The location variable was not defined when creating the error message
for version mismatch between rips and application.
2021-08-03 13:29:03 +02:00
Magne Sjaastad 1bacd41037 Add Python linting using black (#7276) 2021-01-26 20:48:01 +01:00
Gaute Lindkvist 493f257e5e Fix wrong use of "is" and "is not" in Python if-statements 2021-01-12 11:23:30 +01:00
Gaute Lindkvist 2de5c9ce0b Move GrpcInterface into top level 2021-01-11 15:27:45 +01:00