Skip to content

bcm283x pulseio _mq.receive stuck after SIGINT(CTRL-C) #89

@iwanicki92

Description

@iwanicki92

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 in bcm283x/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:

<RepeatTimer(Thread-1, started 1985381440)>
  File "/usr/lib/python3.9/threading.py", line 912, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/home/iwans/repozytorium_github/sensors-and-screen-controller/dht_bug.py", line 16, in run
    self.function(*self.args, **self.kwargs)
  File "/home/iwans/repozytorium_github/sensors-and-screen-controller/dht_bug.py", line 27, in print_data
    humidity = dht.humidity
  File "/home/iwans/repozytorium_github/.venv/lib/python3.9/site-packages/adafruit_dht.py", line 284, in humidity
    self.measure()
  File "/home/iwans/repozytorium_github/.venv/lib/python3.9/site-packages/adafruit_dht.py", line 219, in measure
    pulses = self._get_pulses_pulseio()
  File "/home/iwans/repozytorium_github/.venv/lib/python3.9/site-packages/adafruit_dht.py", line 148, in _get_pulses_pulseio
    while self.pulse_in:
  File "/home/iwans/repozytorium_github/.venv/lib/python3.9/site-packages/adafruit_blinka/microcontroller/bcm283x/pulseio/PulseIn.py", line 168, in __len__
    message = self._wait_receive_msg()
  File "/home/iwans/repozytorium_github/.venv/lib/python3.9/site-packages/adafruit_blinka/microcontroller/bcm283x/pulseio/PulseIn.py", line 104, in _wait_receive_msg
    message = self._mq.receive(block=True, type=type)

Installed adafruit packages:

Adafruit-Blinka==8.19.0
adafruit-circuitpython-busdevice==5.2.4
adafruit-circuitpython-dht==4.0.0
adafruit-circuitpython-requests==1.13.2
adafruit-circuitpython-typing==1.9.2
Adafruit-PlatformDetect==3.46.0
Adafruit-PureIO==1.1.10
pyftdi==0.54.0
pyserial==3.5
pyusb==1.2.1
rpi-ws281x==4.3.4
RPi.GPIO==0.7.1
sysv-ipc==1.1.0
typing-extensions==4.5.0

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.

import signal
import time
import board
from adafruit_dht import DHT22

if __name__ == "__main__":
    dht = DHT22(board.D4)
    def sigint_handler(_1, _2):
        pass
    signal.signal(signal.SIGINT, sigint_handler)

    while True:
        try:
            print(f"{dht.humidity=}, {dht.temperature=}")
        except:
            pass
        time.sleep(0.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions