I am trying to control two threads in my python code with event objects. In one thread I wait for the other thread to set the event to True and execute while it stays as 'True' and else, do something else. My problem is that the 'else' part of the loop never gets called. Any ideas why? Thank you very much in advance.
I have tried changing the 'while'statement for a 'if' statement without any luck. And I really don't know why this isn't working.
def send_thread(self):
rospy.loginfo('set')
self.event.set()
for cmd in sequence:
Do something
rospy.sleep(2)
rospy.loginfo('saving command in full')
self.U_full.append(self.U_single)
self.event.clear()
def receive_thread(self,msg):
while self.event.wait() == True:
Do something
else:
Do something else
The expected result is that the 'while' part of the recive_thread runs until the event is cleared in the sending_thread and after that, the 'else' part is executed.