Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
882 views
in Technique[技术] by (71.8m points)

terminal - RaspberryPi Shell frozen after Python-Curses (Ctrl-C)

I have a small Python application which gets me some output with simple curses. I want this app to run as long as the user doesn't press a specific button. In the past I just used Ctrl-C to quit my app. And actually, that's still working here too, but apparently I can't get any input into my terminal after quitting (except KeyboardInterrupt).

I tried catching the exception and resetting the curses-settings and some other things. I can't test-run the original app on my Mac, because its using GPIO Pins but the script beneath works on my Mac and after quitting with Ctrl-C everything is fine. On the Pi its causing the same behaviour though.

Thanks in Advance :-)

import time
import curses
import threading
import random
            
class SomeOutputtingThing:
    
    def start(self):
        self.running = True
        threading.Thread(target=self.show_values, daemon=True).start()
    
    def stop(self):
        self.running = False
        
    def show_values(self):
    
        stdscr = curses.initscr()
        curses.noecho()
        curses.cbreak()
        
        try:
            while self.running:
                stdscr.addstr(0,0, "Some valuable Data i want to see: {}".format(random.randint(0,5)))
                stdscr.addstr(1,0, "Some valuable Data i want to see: {}".format(random.randint(0,5)))
                stdscr.refresh()
        finally:
            curses.echo()
            curses.nocbreak()
            curses.endwin()

if __name__ == "__main__":

    foo = SomeOutputtingThing()
    foo.start()
    time.sleep(15)
    foo.stop()
question from:https://stackoverflow.com/questions/65851926/raspberrypi-shell-frozen-after-python-curses-ctrl-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...