IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.6k stars 490 forks source link

Exception ignored in: <bound method Peripheral.__del__ of <bluepy.btle.Peripheral object at 0xb5d0d1d0>> #305

Open PrzemoF opened 5 years ago

PrzemoF commented 5 years ago

I'm getting this once in a while: '''Exception ignored in: <bound method Peripheral.del of <bluepy.btle.Peripheral object at 0xb5d0d1d0>> Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 532, in del self.disconnect() File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 424, in disconnect self._writeCmd("disc\n") File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 275, in _writeCmd self._helper.stdin.flush() BrokenPipeError: [Errno 32] Broken pipe

I can't reduce it to a small test case

kesslera commented 5 years ago

I had the same problem and I think it is caused by the library trying to call disconnect() in the del() method of the peripheral for an already disconnected or deleted device.

I've just added a try-except to the del() :

def __del__(self):
        try:
            self.disconnect()
        except BrokenPipeError as brpip_err:
            pass

it is not pretty, but it does the job

PrzemoF commented 5 years ago

More of the same, just different errors: Exception ignored in: <bound method Peripheral.del of <bluepy.btle.Peripheral object at 0xb5288f10>> Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 532, in del self.disconnect() File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 425, in disconnect self._getResp('stat') File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 377, in _getResp resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout) File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 345, in _waitResp raise BTLEException(BTLEException.INTERNAL_ERROR, "Unexpected response (%s)" % respType) bluepy.btle.BTLEException: Unexpected response (find) Exception ignored in: <bound method Peripheral.del of <bluepy.btle.Peripheral object at 0xb5d7d750>> Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 532, in del self.disconnect() File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 425, in disconnect self._getResp('stat') File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 377, in _getResp resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout) File "/usr/local/lib/python3.4/dist-packages/bluepy-1.2.0-py3.4.egg/bluepy/btle.py", line 345, in _waitResp raise BTLEException(BTLEException.INTERNAL_ERROR, "Unexpected response (%s)" % respType) bluepy.btle.BTLEException: Unexpected response (wr)

theBigGron commented 5 years ago

So after passing on the broken pipe error I end up with:

Got: "rsp=$stat state=$disc mtu=h0 sec='low\n"
Stopping  /home/pi/.local/share/virtualenvs/pi-V9tpwFal/lib/python3.5/site-packages/bluepy/bluepy-helper

Exception: Device disconnected
Trying to recover 

Running  /home/pi/.local/share/virtualenvs/pi-V9tpwFal/lib/python3.5/site-packages/bluepy/bluepy-helper
Sent:  conn 98:07:2D:1D:34:80 public

Got: "rsp=$stat state=$tryconn dst='98:07:2D:1D:34:80 mtu=h0 sec='low\n"
Got: "rsp=$stat state=$disc mtu=h0 sec='low\n"
Stopping  /home/pi/.local/share/virtualenvs/pi-V9tpwFal/lib/python3.5/site-packages/bluepy/bluepy-helper

And my cc2650_stk status light starts blinking red.