Skip to content

Commit cdbace2

Browse files
committed
Use realtime_verify for is_sim / is_rt
Everything else is anoying / unrelaiable
1 parent bdd3ef9 commit cdbace2

3 files changed

Lines changed: 12 additions & 47 deletions

File tree

lib/python/hal.py

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

3030
import _hal
3131
from _hal import *
32-
import warnings
33-
import os
34-
35-
def __getattr__(name):
36-
if name == 'is_rt':
37-
warnings.simplefilter('always', DeprecationWarning)
38-
warnings.warn(f"{name} is deprecated, use get_realtime_type() instead", DeprecationWarning)
39-
warnings.simplefilter('default', DeprecationWarning)
40-
41-
#We the hal to be initialized to use get_realtime_type()
42-
#If it is not initialized, create a component which will inizialize it
43-
#It will be cleaned up imediately
44-
comp_name=f"halpy{os.getpid()}"
45-
if not is_initialized():
46-
c=component(comp_name);
47-
48-
t = get_realtime_type()
49-
if t == REALTIME_TYPE_UNINITIALIZED:
50-
warnings.warn("Unable to check realtime status, not initialized", Warning)
51-
return False
52-
elif t == REALTIME_TYPE_NONE:
53-
return False
54-
else:
55-
return True
56-
if name == 'is_sim':
57-
warnings.simplefilter('always', DeprecationWarning)
58-
warnings.warn(f"{name} is deprecated, use get_realtime_type() instead", DeprecationWarning)
59-
warnings.simplefilter('default', DeprecationWarning)
60-
61-
#We the hal to be initialized to use get_realtime_type()
62-
#If it is not initialized, create a component which will inizialize it
63-
#It will be cleaned up imediately
64-
comp_name=f"halpy{os.getpid()}"
65-
if not is_initialized():
66-
c=component(comp_name);
67-
68-
t = get_realtime_type()
69-
if t == REALTIME_TYPE_UNINITIALIZED:
70-
warnings.warn("Unable to check realtime status, not initialized", Warning)
71-
return True
72-
elif t == REALTIME_TYPE_NONE:
73-
return True
74-
else:
75-
return False
76-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
7732

7833
class _ItemWrap(object):
7934
def __new__(cls, item):

scripts/realtime.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ Verify(){
234234

235235
if [ $HAS_REALTIME = true ]; then
236236
echo "Realtime detected"
237-
exit 0
237+
return 0
238238
else
239239
echo "No realtime detected"
240-
exit 1
240+
return 1
241241
fi
242242
}
243243

src/hal/halmodule.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,16 @@ PyMODINIT_FUNC PyInit__hal(void)
24012401
PyModule_AddIntConstant(m, "REALTIME_TYPE_XENOMAI", REALTIME_TYPE_XENOMAI);
24022402
PyModule_AddIntConstant(m, "REALTIME_TYPE_XENOMAI_EVL", REALTIME_TYPE_XENOMAI_EVL);
24032403

2404+
//Call realtime verify to gather realtime status
2405+
//Most probably we don't have realtime running yet
2406+
int ret = system("realtime verify > /dev/null");
2407+
int exit_stat = WEXITSTATUS(ret);
2408+
if(exit_stat != 0 && exit_stat != 1){
2409+
PyErr_Format(PyExc_RuntimeError, "realtime verify failed, system() return value %i / exit %i", ret, exit_stat);
2410+
}
2411+
PyModule_AddIntConstant(m, "is_rt", exit_stat == 0);
2412+
PyModule_AddIntConstant(m, "is_sim", exit_stat != 0);
2413+
24042414
PyModule_AddIntConstant(m, "is_kernelspace", rtapi_is_kernelspace());
24052415
PyModule_AddIntConstant(m, "is_userspace", !rtapi_is_kernelspace());
24062416

0 commit comments

Comments
 (0)