Bottle:BrokenPipeError:[Errno 32]管道损坏

问题描述 投票:1回答:1

我编写了一个小小的Python,它应该通过使用LED灯带做一些事情来对某些Webhook做出反应。我正在使用在启动时启动的Xterm窗口在运行Raspbian的Raspberry Pi上运行此程序。该程序将启动并运行几分钟,但随后将停止工作。我已经进行了一些调试,发现该程序有时会在一个CPU内核上使用100%,有时会吐出“ BrokenPipeError:[Errno 32]管道损坏”错误,有时它什么也不做。我尝试过单独运行发送到LED灯带,并且效果很好。我也尝试过使用不同的Bottle服务器,但也无济于事。

这里是我发现的回溯:

*Private IP* - - [25/Mar/2020:17:21:31 +0200] "GET /setcolor/255/0/0 HTTP/1.1" 200 0 "-" "python-requests/2.23.0"
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/bottle.py", line 868, in _handle
    return route.call(**args)
  File "/home/pi/.local/lib/python3.7/site-packages/bottle.py", line 1748, in wrapper
    rv = callback(*a, **ka)
  File "/home/pi/Documents/Python/LED-Webhooks.py", line 59, in index
    light.mode = magichue.NORMAL
  File "/home/pi/.local/lib/python3.7/site-packages/magichue/magichue.py", line 357, in mode
    self._set_mode(mode)
  File "/home/pi/.local/lib/python3.7/site-packages/magichue/magichue.py", line 369, in _set_mode
    receive=self.confirm_receive_on_send
  File "/home/pi/.local/lib/python3.7/site-packages/magichue/magichue.py", line 114, in _send_with_checksum
    self._send(data)
  File "/home/pi/.local/lib/python3.7/site-packages/magichue/magichue.py", line 105, in _send
    return self._sock.send(data)
BrokenPipeError: [Errno 32] Broken pipe

这里是整个程序:

import time
import datetime
import magichue
from bottle import route, run

light = magichue.Light('192.168.1.36')


def flash(r, g, b):
    light.mode = magichue.NORMAL
    light.rgb = (0, 0, 0)
    time.sleep(0.5)
    light.rgb = (r, g, b)
    time.sleep(0.4)
    light.rgb = (0, 0, 0)
    time.sleep(0.5)
    light.rgb = (r, g, b)
    time.sleep(0.4)


def fadein(r, g, b, tr=1):
    light.mode = magichue.NORMAL
    while tr <= 25:
        r = r + 10
        g = g + 10
        b = b + 10
        light.rgb = (r, g, b)
        time.sleep(0.5)
        tr = tr + 1
    else:
        light.rgb = (255, 255, 255)


@route('/flashgreen')
def index():
    print("Im here")
    x = datetime.datetime.now()
    if 10 <= x.hour <= 22:
        time.sleep(0.1)
        light.update_status()
        if light.on:
            pr = light.rgb
            flash(0, 255, 0)
            light.rgb = pr
        else:
            flash(0, 255, 0)
            light.on = False


@route('/fadein')
def index():
    print("Im here")
    fadein(0, 0, 0)


@route('/setcolor/<r>/<g>/<b>')
def index(r, g, b):
    print("Im here")
    light.mode = magichue.NORMAL
    light.rgb = (int(r), int(g), int(b))


run(host='0.0.0.0', port=4783, server='paste')
python-3.x raspberry-pi bottle
1个回答
1
投票

经过大量调试后,Magichue库显然忘记了我的初始声明:

light = magichue.Light('192.168.1.36')

一段时间后。

© www.soinside.com 2019 - 2024. All rights reserved.