Python SimpleActionServer stops unexpectedly (deadlock!)
Hi all,
I'm writing a small piece of code that leverages actionlib, specifically SimpleActionServer. The main intricacy is that I register a preempt callback, but then I set_preempted on another thread (see code below).
However, when the rate of requests is relatively high (~1Hz) sometimes actionlib stops processings new requests. It does not crash, it does not print nor log anything, it just idles.
Below is a simplified version of my code:
class Node():
def __init__(self):
self.server = actionlib.SimpleActionServer(
"Topic",
Action,
execute_cb=self.run,
auto_start=False )
#Variables so that preemption works
self.myLock = threading.Lock()
self.taskID = None
#register preempt callbacks
self.server.register_preempt_callback( self.stop )
#Start actionlib
self.server.start()
def run(self, goal):
with self.myLock:
self.taskID = startTask() #Launch task in another thread
#Wait for task to be completed or killed
if not (self.taskID is None):
wait( self.taskID ) #Wait for task to finish
#Do not allow task to be preempted from now
with self.myLock:
self.taskID = None
# Get actionlib result
result = ActionResult()
getResult(result)
if not valid(result): #valid() defined elsewhere
self.server.set_aborted( result )
elif self.server.is_preempt_requested() :
self.server.set_preempted( result )
else :
self.server.set_succeeded( result )
# Sometimes actionlib will stop processing new requests after this!!
def stop( self ):
with self.myLock:
if ( not ( self.taskID is None ) and self.server.is_preempt_requested() ):
killTask( self.taskID ) # Function defined elsewhere
self.taskID = None
Am I using actionlib in an invalid way? Could this be an actionlib bug?
Thanks, Miguel S.
Just curious, which ROS distro are you using?
It's Fuerte on Ubuntu 12.04
Can you interrupt the program and get a backtrace?
@tfoote See my answer. @IsaacSaito Also present in Groovy in Ubuntu 12.04.