Skip to content

Commit

Permalink
Merge #424
Browse files Browse the repository at this point in the history
424: Do not attempt to close an already closed resources in __del__ r=MatthieuDartiailh a=MatthieuDartiailh

This can mitigate issues such as #416.

Co-authored-by: MatthieuDartiailh <marul@laposte.net>
Co-authored-by: Matthieu Dartiailh <marul@laposte.net>
  • Loading branch information
bors[bot] and MatthieuDartiailh committed Jul 22, 2019
2 parents 54ee914 + 9a56617 commit 3aad98b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PyVISA Changelog
1.10 (unreleased)
-----------------

- avoid attempting to close already closed resources in del PR #424
- add a list_opened_resources method to the ResourceManager PR #415
- use privately stored resource name in Resource class rather than relying on
VisaLibrary PR #415
Expand Down
4 changes: 3 additions & 1 deletion pyvisa/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,8 @@ def __repr__(self):
return '<ResourceManager(%r)>' % self.visalib

def __del__(self):
self.close()
if self._session is not None:
self.close()

def ignore_warning(self, *warnings_constants):
"""Ignoring warnings context manager for the current resource.
Expand All @@ -1606,6 +1607,7 @@ def last_status(self):

def close(self):
"""Close the resource manager session.
"""
try:
logger.debug('Closing ResourceManager (session: %s)', self.session)
Expand Down
3 changes: 2 additions & 1 deletion pyvisa/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def session(self, value):
self._session = value

def __del__(self):
self.close()
if self._session is not None:
self.close()

def __str__(self):
return "%s at %s" % (self.__class__.__name__, self._resource_name)
Expand Down

0 comments on commit 3aad98b

Please sign in to comment.