ROS Qt Interrupted System Call On Plugin Startup
I've recently been working on a python widget for rqt
that creates a separate thread to read joystick data in from a pipe. I've tested it as a standalone python program and confirmed that it's getting valid data. However, when I put it into a python plugin for rqt
that I've already created and tested, it crashes. After some tweaking of the code, it looks like it crashes at the end of the __init__
function in the plugin with IOError: [Errno 4] Interrupted system call
when the pipe read is interrupted.
The initialization is basically:
- Create a joystick object that creates a thread to endlessly read in data from
/dev/input/js0
; start running it - Create thread to endlessly check the Joystick object containing this other thread to look for new data; start running it
- Wait 5 seconds, during which joystick data prints out fine as I would expect
- The 5 Second wait ends,
IOError: [Errno 4] Interrupted system call
is thrown, andrqt
loads as normal
A snippet of the plugin code is below. The Joystick class being referenced creates a thread in the same manner, opens a pipe using self._pipe = open('/dev/local/js0', 'r')
, then reads in raw data for parsing using for character in self._pipe.read(1):
class Joystick(Plugin):
# Variables...
def __init__(self, context):
# Some initialization code here...
#...
# Create the joystick object and run its thread
self._joystick_reader = LinuxJoystickReader()
self._joystick_reader.initialize('/dev/input/js0')
self._joystick_reader.start()
# Create a local thread and run it to print the joystick data
self._joystick_thread_run = True
self._joystick_read_thread = Thread(target=self.pub_joystick, args=())
self._joystick_read_thread.start()
# Sleep, during which the data prints out fine
time.sleep(5)
# -- ERROR --
# File "joystick_class.py" line 35, in read_pipe
# for character in self._pipe.read(1):
# IOError: [Errno 4] Interrupted system call
def pub_joystick(self):
while self._joystick_thread_run:
if self._joystick_reader.has_new_data():
pub_str = str(self._joystick_reader.get_data_array()[0]) + ", " + str(self._joystick_reader.get_data_array()[1])
print pub_str
self._joystick_reader.stop()
Btw you should never sleep during construction but I guess this is just part of your debugging code. Even any long running other operation should be deferred or be performed in a separate thread.
Yes, the sleep is just for debugging purposes (a shot in the dark that paid off), I'm trying to get the separate threads to run on their own without crashing :)