pypylon
pypylon copied to clipboard
The Camera Object Does not Follow the RAII Principle
It is an amazingly helpful library, but I noticed the pypylon.pylon.InstantCamera
class does not follow the RAII principle to open and close a camera. Instead, it leaves the acquisition (and eventual release) of the camera to developer judgement. I am curious if the maintainers had their reason for making this choice, and what possible scenarios are aided by this.
Nonetheless, I thought some developers can benefit from this class that I developed as a context manager wrapper around the existing InstantCamera, that can replace the parent class respecting the Liskov substitution principle and can be used within a with
block.
class CameraContext(py.InstantCamera):
"""This class is to respect the RAII principle of managing the camera resource."""
def __enter__(self):
"""Acquire the camera."""
self.Open()
def __exit__(self, exc_type, exc_val, exc_tb):
"""Release the camera."""
self.Close()
I can also add the methods to the existing class, if the maintainers are accepting contributions from the community. Kindly let me know the contributing guidelines for that.