From ec9fd9eb5fd9c0f002d5c3dc16d5ed37f0684694 Mon Sep 17 00:00:00 2001 From: kznr Date: Tue, 18 Dec 2018 17:54:53 +0900 Subject: [PATCH] Resolve issue #72 --- README.rst | 24 +++++++++++++++++++----- src/harvesters/core.py | 6 ------ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index b747ca7..b7bb635 100644 --- a/README.rst +++ b/README.rst @@ -615,7 +615,9 @@ The following code block shows Harvester Core is running on IPython. An acquired In [14]: ia.destroy() - In [15]: quit + In [15]: h.reset() + + In [16]: quit (genicam) kznr@Kazunaris-MacBook:~% #################### @@ -747,14 +749,26 @@ And the following code disconnects the connecting device from the image acquirer ia.destroy() -Now you can quit the program! Please not that the image acquirer also supports the ``with`` statement. So you may write program as follows: +If you finished working with the ``Harvester`` object, then release the acquired resources calling the ``reset`` method: + +.. code-block:: python + + h.reset() + +Now you can quit the program! Please not that ``Harvester`` and ``ImageAcquirer`` also support the ``with`` statement. So you may write program as follows: .. code-block:: python - with h.create_image_acquirer(0) as ia: - # Work, work, and work with the ia object. + with Harvester() as h: + with h.create_image_acquirer(0) as ia: + # Work, work, and work with the ia object. + # The ia object will automatically call the destroy method + # once it goes out of the block. + + # The h object will automatically call the reset method + # once it goes out of the block. - # the ia object will automatically call the destroy method. +This way prevents you forget to release the acquired external resources. If this notation doesn't block your use case then you should rely on the ``with`` statement. *********************** Reshaping a NumPy array diff --git a/src/harvesters/core.py b/src/harvesters/core.py index 760fd5c..b8db086 100644 --- a/src/harvesters/core.py +++ b/src/harvesters/core.py @@ -1385,9 +1385,6 @@ def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): - self.__del__() - - def __del__(self): self.destroy() @property @@ -2196,9 +2193,6 @@ def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): - self.__del__() - - def __del__(self): self.reset() @property