python-3.x - 瓶子:BrokenPipeError:[Errno 32] 断管
问题描述
我编写了一个小 Python,它应该通过使用 LED-Strip 做一些事情来对一些 webhook 做出反应。我使用启动时启动的 Xterm 窗口在运行 Raspbian 的 Raspberry Pi 上运行它。该程序启动并运行了几分钟,但随后停止工作。我做了一些调试,发现有时程序会在一个 CPU 内核上使用 100%,有时它会吐出“BrokenPipeError: [Errno 32] Broken pipe”错误,有时它什么也不做。我试过单独运行发送到 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')
解决方案
经过大量调试后解决,显然Magichue库忘记了我最初的声明:
light = magichue.Light('192.168.1.36')
一段时间后。
推荐阅读
- mysql - Mysql子查询返回null
- maven - 将文件从 Maven 元数据插件过滤到部署
- android - 怎么删除这个文件到
- dart - Flutter Codelab 如何将 SizeTransition 转换为 FadeTransition
- javascript - 给定一个为嵌套 javascript 对象返回“[prop1][prop2][prop3]”的函数,我如何获取 object[prop1][prop2][prop3] 的值?
- html - 如何移动具有相对定位的图像?
- python - 根据另一个字典中的键增加字典中的值
- c# - 需要文件数据的单元测试类?
- objective-c - 如何在objective-c中正确地printf float (*)()?
- php - 在 If-else Scoop 中返回一个数组