Trouble with ros and cython (update)
Hello list,
I really am struggling with using ROS (Indigo on Ubuntu 14.04) and some code that uses Cython (version 0.20.1post0) to bind a C-library to python. In an earlier attempt I used swig, but I also failed in getting that to work reliably.
If I use the code generated with Cython in python without using anything from ROS, everything is fine, no errors or crashes.
But as soon as I use ROS, even only something like 'rospy.init_node('nodename')', there are occasional crashes or hangs. Say something like every 10-th start of that program.
I also fiddled with signal catching of e.g. signal.SIGSEGV, which work when I send it when the program is running, but is not working when a sigsegv really happens (I think).
Does anyone know is there are some clever tricks done in ROS (of Cython) that could explain this? Or a pointer how to attack this? I really am at a loss here.
UPDATE:
I found that the crashes almost always occur in the sleep function of rospy.Rate. I find it strange that initially calling some (Cython) function make this sleep function crash.
Here a stripped version of the program that still has the crashes.
rospy.init_node('peratestinit')
RTM2v_Init()
for DevNr in range(4):
rtm_usb_ReadStdMsg(DevNr)
rtm_usb_Read_ready(DevNr)
rtm_usb_SendStdMsg(DevNr,0, 0, 0, 0);
rate = 50
r = rospy.Rate(rate)
k = 0 ;running = True
while running == True:
# do some (control) stuff, including some (Cython) rtm_usb function calls
j = 0
for i in range(1000):
j += math.sin(i)
print 'insleep', j
r.sleep()
print 'uitsleep'
k = k+1
if k == 10:
running = False
The rtm functions are communication with a robot arm using Cython generated code. The last printout almost always is the print from direcly before the r.sleep().
If I remove the rospy.init_node and use the regular python time.sleep() instead of r.sleep(), so no ROS at all, everything works!
???
Thanks in advance, Sietse