Skip to content

Commit 52c64cf

Browse files
committed
Deprecate is_sim / is_rt and replace by lcnc_realtime.py
lcnc_realtime.verify() should be used instead of hal.is_rt
1 parent 440a5fd commit 52c64cf

14 files changed

Lines changed: 94 additions & 20 deletions

File tree

docs/po4a.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
[type: AsciiDoc_def] src/config/moveoff.adoc $lang:build/adoc/$lang/config/moveoff.adoc
5252
[type: AsciiDoc_def] src/config/pncconf.adoc $lang:build/adoc/$lang/config/pncconf.adoc
5353
[type: AsciiDoc_def] src/config/python-hal-interface.adoc $lang:build/adoc/$lang/config/python-hal-interface.adoc
54+
[type: AsciiDoc_def] src/config/python-lcnc_realtime.adoc $lang:build/adoc/$lang/config/python-lcnc_realtime.adoc
5455
[type: AsciiDoc_def] src/config/python-interface.adoc $lang:build/adoc/$lang/config/python-interface.adoc
5556
[type: AsciiDoc_def] src/config/stepconf.adoc $lang:build/adoc/$lang/config/stepconf.adoc
5657
[type: AsciiDoc_def] src/config/stepper.adoc $lang:build/adoc/$lang/config/stepper.adoc

docs/src/Master_Documentation.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ include::config/python-interface.adoc[]
300300

301301
include::config/python-hal-interface.adoc[]
302302

303+
include::config/python-lcnc_realtime.adoc[]
304+
303305
include::gui/gstat.adoc[]
304306

305307
include::gui/vismach.adoc[]

docs/src/Submakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ DOC_SRCS_EN := \
141141
config/moveoff.adoc \
142142
config/pncconf.adoc \
143143
config/python-hal-interface.adoc \
144+
config/python-lcnc_realtime.adoc \
144145
config/python-interface.adoc \
145146
config/stepconf.adoc \
146147
config/stepper-diagnostics.adoc \

docs/src/config/python-hal-interface.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ System information:
6666
* `hal.is_userspace` - Inverted `hal.is_kernelspace`
6767
* `hal.kernel_version` - A string specifying the real-time kernel version if `hal.is_kernelspace` is one.
6868
Otherwise it specifies `"Not Available"`.
69-
* `hal.is_rt` - One (1) if the system runs in real-time, otherwise zero (0)
70-
* `hal.is_sim` - Inverted `hal.is_rt`
69+
* `hal.is_rt` - One (1) if the system runs in real-time, otherwise zero (0) *DEPRECATED*: Use `lcnc_realtime.verify()`
70+
* `hal.is_sim` - Inverted `hal.is_rt` *DEPRECATED*: Use `lcnc_realtime.verify()`
7171

7272
=== hal methods
7373

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
:lang: en
2+
:toc:
3+
4+
[[cha:python-lcnc_realtime]]
5+
= Python module for managing the realtime backend
6+
7+
This documentation describes the `lcnc_realtime` Python module, which provides
8+
a Python API for managing the realtime backend.
9+
10+
This is a Python wrapper of the realtime script.
11+
12+
== Basic usage
13+
14+
.Verify realtime capability and check if the realtime backend is running
15+
[source,python]
16+
----
17+
import lcnc_realtime
18+
19+
print("lcnc_realtime.verify " + str(lcnc_realtime.verify()))
20+
print("lcnc_realtime.status " + str(lcnc_realtime.status()))
21+
----
22+
23+
== methods
24+
25+
hal.verify()::
26+
Returns a boolean to indicate whether the system is realtime capable.
27+
28+
hal.status()::
29+
Returns a boolean to indicate whether the realtime backend is running.

docs/src/hal/halmodule.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ Use these to specify details rather then the value they hold.
199199

200200
Read these to acquire information about the realtime system.
201201

202+
* `lcnc_realtime`: See <<cha:python-lcnc_realtime, Python module for managing the realtime backend>>.
202203
* `is_kernelspace`
203-
* `is_rt`
204-
* `is_sim`
205204
* `is_userspace`
205+
* `get_realtime_type()`
206206

207207
// vim: set syntax=asciidoc:

lib/python/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
nf.py
2+
lcnc_realtime.py
23
gscreen
34
gmoccapy/
45
stepconf/

lib/python/hal.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@
2929

3030
import _hal
3131
from _hal import *
32+
import warnings
33+
import lcnc_realtime
34+
35+
def __getattr__(name):
36+
if name == 'is_rt':
37+
warnings.warn(f"{name} is deprecated, use lcnc_realtime.verify() instead", FutureWarning, stacklevel=2)
38+
return lcnc_realtime.verify()
39+
40+
if name == 'is_sim':
41+
warnings.warn(f"{name} is deprecated, use lcnc_realtime.verify() instead", FutureWarning, stacklevel=2)
42+
return not lcnc_realtime.verify()
43+
44+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
3245

3346
class _ItemWrap(object):
3447
def __new__(cls, item):

lib/python/lcnc_realtime.py.in

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Python wrapper of realtime script
2+
# Copyright 2026 Hannes Diethelm <hannes.diethelm@gmail.com>
3+
#
4+
# This program is free software; you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation; either version 2 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
18+
import subprocess
19+
20+
REALTIME="@REALTIME@"
21+
22+
def verify() -> bool:
23+
#Checks if system is realtime compatible
24+
cmd = [REALTIME, "verify"]
25+
ret = subprocess.run(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
26+
if ret.returncode != 0 and ret.returncode != 1:
27+
raise RuntimeError("cmd \"" + " ".join(cmd) + "\" failed with status " + str(ret.returncode))
28+
return ret.returncode==0;
29+
30+
def status() -> bool:
31+
#Status: realtime core running (rtapi_app running or kernel modules active)
32+
#Note: rtapi_app running does not mean realtime compatibility!
33+
cmd = [REALTIME, "status"]
34+
ret = subprocess.run(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
35+
if ret.returncode != 0 and ret.returncode != 1:
36+
raise RuntimeError("cmd \"" + " ".join(cmd) + "\" failed with status " + str(ret.returncode))
37+
return ret.returncode==0;

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ INFILES = \
357357
../tcl/linuxcnc.tcl ../scripts/halrun ../scripts/rip-environment \
358358
../scripts/linuxcncmkdesktop \
359359
../lib/python/nf.py \
360+
../lib/python/lcnc_realtime.py \
360361
../share/desktop-directories/linuxcnc-doc.directory \
361362
../share/desktop-directories/linuxcnc-ref.directory \
362363
../share/desktop-directories/linuxcnc-cnc.directory \

0 commit comments

Comments
 (0)