KillSwitch to Kill an Application

Posted over 1 year ago by Oliver.mathews

Post a topic
Solved
O
Oliver.mathews

Hello to everybody,


i'm a newbie in coding with python an den NoaQI API. Since 1999 i code only Java and  i want to learn more about Python and the NaoQi API. 

I habe try to code a "Killswitch" thats kill a running applikation. E.g. i have code an application where the Robot say something and i want to terminate the app by touching the Headsensor.

The Porgramm terminate the app, but it throws Exceptions.

Has anybody an idea or a good notice, what i can make better ??


Thanks in advance and best regards

Oliver


This is the excpetion:


Traceback (most recent call last):
  File "E:\$daten\NAO\Python\ppra01\aufg01\MyTouchTest.py", line 45, in <module>
    myC = MyClass(app)
  File "E:\$daten\NAO\Python\ppra01\aufg01\MyTouchTest.py", line 18, in __init__
    self.mySpeak()
  File "E:\$daten\NAO\Python\ppra01\aufg01\MyTouchTest.py", line 33, in mySpeak
    self.my_tts.say("Hallo sdiufhsfkasdkjasdnaskjfbnsdkfbskfjn")
RuntimeError: Future canceled.
[W] 1677076113.009489 5832 qitype.signal: disconnect: No subscription found for SignalLink 14.
[E] 1677076113.009489 13872 python: Bug: error while getting python error
[E] 1677076113.015617 13872 python: Bug: error while getting python error
[W] 1677076113.015617 7864 qitype.signal: disconnect: No subscription found for SignalLink 0.

And that's my code:


# -*- encoding: UTF-8 -*-
import qi
import sys

class MyClass(object):
   
    def __init__(self, app):
        super(MyClass, self).__init__()
        my_session=app.session
        app.start()
        self.my_tts=my_session.service("ALTextToSpeech")
        self.my_memory = my_session.service("ALMemory")
        self.touch = self.my_memory.subscriber("FrontTactilTouched")
        self.id=self.touch.signal.connect(self.killSwitch)
        self.mySpeak()
               
    def killSwitch(self,qwe):
        bool_okay=self.touch.signal.disconnect(self.id)
        #print("Test")
        try:
            self.my_tts.stopAll()
            app.stop()
            sys.exit(1)      
        except RuntimeError, e:
            print("Fehler:" + e)
   
   
    def mySpeak(self):
        self.my_tts.setVolume(0.1)
        self.my_tts.say("Hallo sdiufhsfkasdkjasdnaskjfbnsdkfbskfjn")
       
   
         
if __name__ == "__main__":
   
    try:
        app = qi.Application(["MyClass", "--qi-url=" + "tcp://192.168.95.80:9559"])
    except RuntimeError:
        print ("Verbindungsfehler")
        sys.exit(1)
       
    myC = MyClass(app)
    app.run()
       

0 Votes


1 Comments

O

Oliver.mathews posted over 1 year ago

I found a solition for me that's works:

I have edit the following Method, i markt the changed code in bold letters:

def mySpeak(self):
        self.my_tts.setVolume(0.1)

        self.my_tts.say("Hallo sdiufhsfkasdkjasdnaskjfbnsdkfbskfjn",_async=True)

def killSwitch(self,qwe):
        self.touch.signal.disconnect(self.id)
        #self.leftDet.signal.disconnect(self.id2)
        #print("Test")
        try:
            self.my_tts.stopAll()
            app.stop()
            os._exit(1)    
        except RuntimeError, e:
            print("Fehler:" + e)


0 Votes

Login or Sign up to post a comment