瓶子:BrokenPipeError:[Errno 32] 断管 [英] Bottle: BrokenPipeError: [Errno 32] Broken pipe

查看:70
本文介绍了瓶子:BrokenPipeError:[Errno 32] 断管的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个小 Python,它应该通过用 LED-Strip 做一些事情来对一些 webhooks 做出反应.我正在使用在启动时启动的 Xterm 窗口在运行 Raspbian 的 Raspberry Pi 上运行它.程序启动并正常运行几分钟,但随后停止工作.我做了一些调试,发现有时程序会在一个 CPU 核心上使用 100%,有时它会吐出BrokenPipeError: [Errno 32] Broken pipe"错误,有时它什么也不做.我试过单独运行发送到 LED 灯条,效果很好.我也尝试过使用不同的 Bottle 服务器,但也无济于事.

I've written a little Python that is supposed to react to some webhooks by doing some stuff with a LED-Strip. I'm running this on a Raspberry Pi running Raspbian using a Xterm window that starts at startup. the program starts and runs fine for a few minutes but then it stops working. I've done some debugging and found that sometimes the program would use 100% on one CPU core, sometimes it spits out the 'BrokenPipeError: [Errno 32] Broken pipe' error and sometimes it just doesn't do anything. I've tried running the sending to LED-strip separately and that worked fine. I've also tried using different Bottle servers but also to no avail.

这是我发现的回溯:

*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')

推荐答案

经过大量调试解决,显然是 Magichue 库忘记了我最初的声明:

Solved after a lot of debugging, apparently the Magichue library forgets my initial declaration of:

light = magichue.Light('192.168.1.36')

一段时间后.

这篇关于瓶子:BrokenPipeError:[Errno 32] 断管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆