Menu

#159 ctrl+c during GPIO.wait_for_edge doesn't work

New
nobody
None
High
Patch
2018-03-13
2018-03-13
Heiner
No

Code which doesn't work:

!/usr/bin/python3

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

print("PythonScript started ... \n")

Press Enter to have a known starting point for testing

input("Press enter ...")

try:
print("Waiting for Strg-c or GPIO-17 ...\n")
GPIO.wait_for_edge(17, GPIO.RISING, bouncetime=500)

except KeyboardInterrupt as e:
print("ctrl+c pressed ...")

else:
print("GPIO-17 pressed ...")

Output on terminal if ctrl+c is pressed: ^C

If I press the GPIO button 17 after ctrl+c, I see the following output:
ctrl+c pressed ...

It looks like the KeyboardInterrupt is triggered,
but it's hold somewhere and released by pressing the GPIO button.

If I replace the GPIO.wait_for_edge(17,...) command by a input("Press Enter again ...")
the KeyboardInterrupt works correct.
So GPIO.wait_for_edge doesen't work correct with KeyboardInterrupt.

Details of environment:

/etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

uname -a
Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux

Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux

GPIO.RPI_INFO
{'MANUFACTURER': 'Sony', 'PROCESSOR': 'BCM2837', 'P1_REVISION': 3, 'TYPE': 'Pi 3 Model B', 'REVISION': 'a02082', 'RAM': '1024M'}

GPIO.VERSION
'0.6.3'

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.