ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Trouble with ros and cython (update)

asked 2016-06-02 04:17:49 -0500

Sietse gravatar image

updated 2016-06-03 05:36:46 -0500

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.


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.


for DevNr in range(4):
    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
    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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-06-06 08:45:52 -0500

Sietse gravatar image

To answer my own question, I found the error. There was a programming error on the Cython site, and for some reason it only manifested itself when running under ROS.

Thanks for your attention. Sietse

edit flag offensive delete link more


Thanks for reporting back. Can you say anything about whether that programming error has been fixed, is there a work-around, any more detail?

gvdhoorn gravatar image gvdhoorn  ( 2016-06-06 09:03:15 -0500 )edit

It was an error on my part, not in Cython itself. I used a C-function with a (void *) parameter with which data should be returned in a wrong way.

By the way, I do this to get our PERA (Philips Experimental Robot Arm) under ROS control. There should be such an arm in Delft if I am correct.

Sietse gravatar image Sietse  ( 2016-06-06 13:24:51 -0500 )edit

Question Tools



Asked: 2016-06-02 04:17:49 -0500

Seen: 501 times

Last updated: Jun 06 '16