Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit precise raise an ValueError exception #165

Open
corus87 opened this issue Jul 14, 2020 · 4 comments · May be fixed by #167
Open

Exit precise raise an ValueError exception #165

corus87 opened this issue Jul 14, 2020 · 4 comments · May be fixed by #167

Comments

@corus87
Copy link

corus87 commented Jul 14, 2020

Hi,
when I exit precise with a keyboard interrupt, it always raise an exception.
I already tried to catch it but without success. Would be nice to have a way to exit it without any exception.

Exception ignored in: <module 'threading' from '/home/pi/precise_trigger/precise-engine/threading.pyc'>
Traceback (most recent call last):
  File "threading.py", line 1279, in _shutdown
KeyboardInterrupt
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/dist-packages/precise_runner/runner.py", line 236, in _handle_predictions
    prob = self.engine.get_prediction(chunk)
  File "/usr/local/lib/python3.7/dist-packages/precise_runner/runner.py", line 67, in get_prediction
    return float(self.proc.stdout.readline())
ValueError: could not convert string to float: 

I hope someone got a hint for me how to catch this exception.
Thanks.

@MatthewScholefield
Copy link
Collaborator

Hi, what code/command are you running? When I used precise-listen this doesn't happen for me.

@corus87
Copy link
Author

corus87 commented Jul 18, 2020

Hi @MatthewScholefield ,
this happens for me on the RPi, when running a simple code like this one:

from precise_runner import PreciseRunner, ReadWriteStream, PreciseEngine
import time

class Precise():    
    def __init__(self):
        # engine data:      https://github.com/mycroftai/precise-data/tree/dist
        # precise models:   https://github.com/MycroftAI/precise-data/tree/models?files=1
        sensitivity = float(0.5)
        trigger_level = int(3)
        model_path = "models/hey-mycroft.pb"
        engine_path = "precise-engine/precise-engine"
        engine = PreciseEngine(engine_path, model_path)

        self.stream = ReadWriteStream()

        self.runner = PreciseRunner(engine,
                                    sensitivity=sensitivity,
                                    trigger_level=trigger_level,
                                    on_activation=self.on_activation)
        self.runner.start()
        time.sleep(10) # Sleep a moment to importing tensorflow on RPi
        print("ready")

        while True:
            data = self.stream.read()
            if len(data) > 1:
                self.update_runner(data)
            time.sleep(0.01)

    def update_runner(self, data):
        self.stream.write(data)

    def on_activation(self):
        print("Activation!")

Precise()

Whenever I exit the code with ctrl + c it raises the ValueError

@MatthewScholefield MatthewScholefield linked a pull request Jul 18, 2020 that will close this issue
@MatthewScholefield
Copy link
Collaborator

MatthewScholefield commented Jul 18, 2020

Hi, can you test using the code proposed in #167?:

pip3 install git+https://github.com/matthewscholefield/mycroft-precise@feature/improved-subprocess-parsing#subdirectory=runner

(if you are using precise-runner from a local install, remember to fix your installation afterwards with pip3 install -e path/to/mycroft-precise/runner)

@corus87
Copy link
Author

corus87 commented Jul 18, 2020

Thanks @MatthewScholefield this branch actually works, no more ValueError on exit :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants