def get_image(tgtbox, boxes_rpc, width=648):
box = _get_box_rpc(tgtbox, boxes_rpc)
if box.lock_exists():
# must yield then return in a generator function
yield template('error', errormsg="It looks like an experiment is currently running on this box. Image capture only works while the box is idle.")
return
try:
try:
box.start_img_stream(width)
except OSError as e:
# must yield then return in a generator function
yield template('error', errormsg="Failed to start image stream capture.", exception=e)
return
# all set; carry on
response.set_header('Content-type', 'multipart/x-mixed-replace; boundary=atlesframe')
while True:
if box.lock_exists():
return
time.sleep(0.5)
imgdata = box.get_image()
if imgdata is None:
return
if len(imgdata) < 16:
continue # ignore dud frames
yield b"\n".join([b"--atlesframe", b"Content-Type: image/jpeg", b"", imgdata, b""])
finally:
box.stop_img_stream()
评论列表
文章目录