jasperproject / jasper-client

Client code for Jasper voice computing platform
MIT License
4.53k stars 1.01k forks source link

shutdown jasper #540

Open ucy74 opened 8 years ago

ucy74 commented 8 years ago

This shuts jasper down:

import subprocess
proc = subprocess.Popen(["pkill", "-f", "jasper.py"], stdout=subprocess.PIPE)
proc.wait()

I was creating module named Shutdown.py based on Life.py I was adding words down, shut and shutdown to _keywordphrases file and running boot.sh script at the end. File location: ~/jasper/client/modules/Shutdown.py

# -*- coding: utf-8-*-
import random
import sys
import re
import subprocess

WORDS = ["SHUTDOWN", "SHUT", "DOWN"]

def handle(text, mic, profile):
    """
        Responds to user-input, typically speech text, by shuting down jasper

        Arguments:
        text -- user-input, typically transcribed speech
        mic -- used to interact with the user (for both input and output)
        profile -- contains information related to the user (e.g., phone
                   number)
    """
    messages = ["I'm going down.",
                "Shuting down now.",
                "Bye Bye."]

    message = random.choice(messages)
    mic.say(message)

    proc = subprocess.Popen(["pkill", "-f", "jasper.py"], stdout=subprocess.PIPE)
    proc.wait()

def isValid(text):
    """
        Returns True if the input is related to the jasper's quit.

        Arguments:
        text -- user-input, typically transcribed speech
    """
    return bool(re.search(r'\bshut down\b', text, re.IGNORECASE))
glop102 commented 8 years ago

Nice idea, though there is probably a more elegnat solution to shutdown japser. Perhaps doing sys.exit(0) would work, and seems more appropriate

ucy74 commented 8 years ago

Belive me, I was testing all elegant python exits :-) In generall, they exit only curent module script. Only this one above works for me for whole jasper exit.

glop102 commented 8 years ago

perhaps there should be a shutdown path added into the main jasper client. This would then give plugins a chance to save information in the shutdown sequence, if they need it, by making their own self.shutdown() method of some sort.

is this something that would work for what you are thinking about?