|
137 | 137 | " return await RobotClient.with_channel(channel, RobotClient.Options(refresh_interval=10, log_level=logging.FATAL))\n", |
138 | 138 | "\n", |
139 | 139 | "\n", |
140 | | - "robot = await connect_with_channel()\n", |
141 | | - "print(robot.resource_names)\n", |
142 | | - "await robot.close()" |
| 140 | + "async with await connect_with_channel() as robot:\n", |
| 141 | + " print(robot.resource_names)" |
143 | 142 | ] |
144 | 143 | }, |
145 | 144 | { |
|
163 | 162 | "from viam.media.video import CameraMimeType\n", |
164 | 163 | "from viam.media.utils.pil import viam_to_pil_image\n", |
165 | 164 | "\n", |
166 | | - "robot = await connect_with_channel()\n", |
167 | | - "camera = Camera.from_robot(robot, \"camera0\")\n", |
168 | | - "image = await camera.get_image(CameraMimeType.JPEG)\n", |
169 | | - "pil = viam_to_pil_image(image)\n", |
170 | | - "pil.save(\"foo.png\")\n", |
171 | | - "\n", |
172 | | - "# Don't forget to close the robot when you're done!\n", |
173 | | - "await robot.close()" |
| 165 | + "async with await connect_with_channel() as robot:\n", |
| 166 | + " camera = Camera.from_robot(robot, \"camera0\")\n", |
| 167 | + " image = await camera.get_image(CameraMimeType.JPEG)\n", |
| 168 | + " pil = viam_to_pil_image(image)\n", |
| 169 | + " pil.save(\"foo.png\")" |
174 | 170 | ] |
175 | 171 | }, |
176 | 172 | { |
|
215 | 211 | "\n", |
216 | 212 | "\n", |
217 | 213 | "async def vision():\n", |
218 | | - " robot = await connect_with_channel()\n", |
219 | | - " vision = VisionClient.from_robot(robot)\n", |
220 | | - " detections = await vision.get_detections_from_camera(\"camera_1\", \"detector_1\")" |
221 | | - ] |
222 | | - }, |
223 | | - { |
224 | | - "cell_type": "markdown", |
225 | | - "metadata": {}, |
226 | | - "source": [ |
227 | | - "At the end, don't forget to close the connection" |
228 | | - ] |
229 | | - }, |
230 | | - { |
231 | | - "cell_type": "code", |
232 | | - "execution_count": 5, |
233 | | - "metadata": {}, |
234 | | - "outputs": [], |
235 | | - "source": [ |
236 | | - "async def cleanup():\n", |
237 | | - " await robot.close()" |
| 214 | + " async with await connect_with_channel() as robot:\n", |
| 215 | + " vision = VisionClient.from_robot(robot)\n", |
| 216 | + " detections = await vision.get_detections_from_camera(\"camera_1\", \"detector_1\")" |
238 | 217 | ] |
239 | 218 | }, |
240 | 219 | { |
|
0 commit comments