无法使用 Raspistill 和 Raspberry Pi 捕获 Python 网络共享异常
Trouble trapping Python network share exception with Raspistill and Raspberry Pi
请帮助我在以下场景中使用子流程时处理异常。我相信你们中的许多人都能想出一些非常高级的异常陷阱,但我真的在寻找基本知识,以便随着时间的推移我可以以此为基础。此代码正在将 jpeg 图像写入已安装的 windows 网络共享。我特意切换了共享的 Read/Write 权限,基本上拒绝了 Pi 访问。我不希望我的程序在没有良好存储位置的情况下喷出它的数字内脏,而只是向我传递一条明智的消息。
snap_pic = 'raspistill -t 1200 -a '+pic_tag+' -ae 50,0x00,0x8080FF -o '+file_path
try:
subprocess.check_call(snap_pic, shell=True)
except subprocess.CalledProcessError:
print ( 'Cannot write to network storage' )
sys.exc_clear()
else:
print ( 'Image number '+image_no+' being processed' )
今天晚上之前我什至不知道"subprocess"是什么,我用os.system来调用'snap_pic'。我看到了一些诱人的限制,所以在这里我试图加强我的小游戏。
我应该在这里使用 .call 还是 .check_call?
无论连接是否存在,我的 "except" 命令总是被绕过。
我是否必须为此代码段的每次迭代清除这些行的错误标志?
一如既往,非常感谢您的帮助。
尝试使用 PiCamera Python package。与使用子流程相比,使用起来更简单、更干净。
下面是演示如何拍照的文档中的一个基本示例:
import time
import picamera
with picamera.PiCamera() as camera:
camera.resolution = (1280, 720)
camera.start_preview()
camera.exposure_compensation = 2
camera.exposure_mode = 'spotlight'
camera.meter_mode = 'matrix'
camera.image_effect = 'gpen'
# Give the camera some time to adjust to conditions
time.sleep(2)
camera.capture('foo.jpg')
camera.stop_preview()
请帮助我在以下场景中使用子流程时处理异常。我相信你们中的许多人都能想出一些非常高级的异常陷阱,但我真的在寻找基本知识,以便随着时间的推移我可以以此为基础。此代码正在将 jpeg 图像写入已安装的 windows 网络共享。我特意切换了共享的 Read/Write 权限,基本上拒绝了 Pi 访问。我不希望我的程序在没有良好存储位置的情况下喷出它的数字内脏,而只是向我传递一条明智的消息。
snap_pic = 'raspistill -t 1200 -a '+pic_tag+' -ae 50,0x00,0x8080FF -o '+file_path
try:
subprocess.check_call(snap_pic, shell=True)
except subprocess.CalledProcessError:
print ( 'Cannot write to network storage' )
sys.exc_clear()
else:
print ( 'Image number '+image_no+' being processed' )
今天晚上之前我什至不知道"subprocess"是什么,我用os.system来调用'snap_pic'。我看到了一些诱人的限制,所以在这里我试图加强我的小游戏。 我应该在这里使用 .call 还是 .check_call? 无论连接是否存在,我的 "except" 命令总是被绕过。 我是否必须为此代码段的每次迭代清除这些行的错误标志?
一如既往,非常感谢您的帮助。
尝试使用 PiCamera Python package。与使用子流程相比,使用起来更简单、更干净。
下面是演示如何拍照的文档中的一个基本示例:
import time
import picamera
with picamera.PiCamera() as camera:
camera.resolution = (1280, 720)
camera.start_preview()
camera.exposure_compensation = 2
camera.exposure_mode = 'spotlight'
camera.meter_mode = 'matrix'
camera.image_effect = 'gpen'
# Give the camera some time to adjust to conditions
time.sleep(2)
camera.capture('foo.jpg')
camera.stop_preview()