avoid using print() function
还没有人认领这个 Issue。
评估
调研方向
打开 brping/device.py 并检查 connect_serial(),包括两处 print 调用和现有的异常路径。测试设备缺失和成功打开这两种情况,以确认前者会按描述引发异常,而后者不再写入 stdout。
由索引模型根据 Issue 内容生成。
描述
This is just a copy of connect_serial() method from brping/device.py (ver 0.1.5)
def connect_serial(self, device_name: str, baudrate: int =115200):
if device_name is None:
print("Device name is required")
return
try:
print("Opening %s at %d bps" % (device_name, baudrate))
## Serial object for device communication
# write_timeout fixes it getting stuck forever atempting to write to
# /dev/ttyAMA0 on Raspberry Pis, this raises an exception instead.
self.iodev = serial.Serial(device_name, baudrate, write_timeout=1.0)
self.iodev.send_break()
time.sleep(0.001)
self.iodev.write("U".encode("ascii"))
except Exception as exception:
raise Exception("Failed to open the given serial port: {0}".format(exception))
The request here is:
Kindly avoid using the print function in a library like this. If the device name is required, it should be handled as an exception, not with a print and return:
raise ValueError("Device name is required")
And the next print is indeed a logging:
logger.info("Opening %s at %d bps", device_name, baudrate)
I've had to use workarounds to prevent these prints from being sent to my app's stdout:
def brping_muted_print(*args, **kw):
if len(args) == 1:
args = args[0]
log('brping: %s', args)
# brping module uses raw print statements for logging
# with this trick, we turn them into proper logs
brping.device.print = brping_muted_print
Thanks
- 主要语言
- Python
- 星标
- 60
- 派生
- 39
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bluerobotics/ping-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
bluerobotics/ping-python#74 ·
-
难度 2/5 1-3 小时 新手友好度 25/100
bluerobotics/ping-python#171 ·
-
set sound speed可能重新可做 @RaulTrombin 于 232 天前认领,目前没有进行中的 PR。 未关闭
bluerobotics/ping-python#169 · 2 条评论 · 已指派 1 人 ·
-
难度 2/5 1-3 小时 新手友好度 48/100
bluerobotics/ping-python#167 ·
-
难度 4/5 3-5 天 新手友好度 32/100
bluerobotics/ping-python#159 ·
查看 bluerobotics/ping-python 的全部 Issue
相似的 Issue
-
New Internship未关闭new_internship
难度 1/5 1 小时以内 新手友好度 70/100
-
[BUG] Reports tab: "Unban" button tooltip shows raw `{{ip}}` placeholder instead of the IP address未关闭bug javascript ui
难度 2/5 1-3 小时 新手友好度 68/100
bunkerity/bunkerweb#4001 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 92/100
PedestrianDynamics/pyFDS-Evac#476 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
google/differential-privacy#516 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
adobe-fonts/source-serif#153 ·