-
Notifications
You must be signed in to change notification settings - Fork 64
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
bcm283x pulseio _mq.receive stuck after SIGINT(CTRL-C) #89
Comments
Try checking if the PulseIO subprocess is alive before calling while True:
try:
if dht.pulse_in._process.poll() == 0:
print("CircuitPython PulseIn subprocess was closed!")
break
print(f"{dht.humidity=}, {dht.temperature=}")
except:
pass
time.sleep(0.2) This happens because signal.SIGINT does not close your application, it only requests it to close. So if the PulseIO subprocess closes before your program, and it also so happens that your program is in the middle or before |
Your code works (I could also use print(f"{dht.humidity=}")
time.sleep(2)
print(f"{dht.temperature=}") then I'd need to check if I have to stop before every call to dht (and possibly others). I guess I could just catch KeyboardInterrupt #!/usr/bin/env python3
import signal
import sys
import time
import board
from adafruit_dht import DHT22
if __name__ == "__main__":
dht = DHT22(board.D4)
while True:
try:
print(f"{dht.humidity=}", end=", ")
sys.stdout.flush()
time.sleep(2)
print(f"{dht.temperature=}")
except KeyboardInterrupt as e:
break
time.sleep(0.2)
print("Cleanup") Or maybe add signal handler and raise custom interrupt exception. My original use case was a little more complicated where main thread started multiple I stopped working on this project over a year ago so it's not a priority but I guess at least a note in documentation or readme that using PulseIO library (and any other that uses it) is not safe after receiving SIGINT (because |
I'm not sure if it's DHT or pulseio fault but sometimes when using CTRL-C(with custom signal handler) program gets stuck on
self._mq.receive(block=True, type=type)
line inbcm283x/pulseio/PulseIn.py
file, ps prints:libgpiod_pulsei <defunct>
and sometimes before getting stuck it prints line of numbers e.g.73, 51, 75, 50, 75, 53, 26, 53, 26, 51, 73, 52, 73, 53, 26, 53, 26, 53, 26, 51, 27, 52, 26, 53, 26, 53, 26, 53, 26, 51, 28, 51, 73, 52, 73, 53, 73, 52, 73, 51, 74, 52, 73, 53, 73, 54, 26, 51, 74, 52, 73, 51, 75, 53, 26, 52, 27, 51, 73, 53, 26, 51, 75, 53
.Python version:
Python 3.9.2
OS:
Raspbian GNU/Linux 11 (bullseye)
Kernel:
Linux 5.15.61-v7+
Architecture:
armv7l
Hardware:
Raspberry Pi 3 Model B V1.2
DHT22:
ASAIR AM2302 SNE1222402511-J
Thread stacktrace:
Installed adafruit packages:
Minimal code to replicate problem(stacktrace is from different code run on another thread so I can detect when it hangs and print stacktrace).
Run code, press CTRL-C and after a while(couple seconds) program should hang.
The text was updated successfully, but these errors were encountered: