Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
test_context close file handle
Browse files Browse the repository at this point in the history
  • Loading branch information
spirit1317 committed Nov 3, 2020
1 parent ca4f8a0 commit 7d63b8e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tango/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def __init__(self, devices_info, server_name=None, instance_name=None,
if not instance_name:
instance_name = server_name.lower()
if db is None:
_, db = tempfile.mkstemp()
handle, db = tempfile.mkstemp()
if host is None:
# IP address is used instead of the hostname on purpose (see #246)
host = get_host_ip()
Expand All @@ -262,6 +262,7 @@ def __init__(self, devices_info, server_name=None, instance_name=None,
if process:
os.environ['ORBscanGranularity'] = '0'
# Attributes
self.handle = handle

This comment has been minimized.

Copy link
@ajoubertza

ajoubertza Nov 6, 2020

Member

handle might be undefined if db was passed in.

self.db = db
self.host = host
self.port = port
Expand All @@ -283,6 +284,7 @@ def __init__(self, devices_info, server_name=None, instance_name=None,
device_cls, device = _device_class_from_field(device_info["class"])
tangoclass = device.__name__
if tangoclass in tangoclass_list:
os.close(self.handle)
os.unlink(self.db)

This comment has been minimized.

Copy link
@ajoubertza

ajoubertza Nov 6, 2020

Member

Now that it takes two calls to clean up the DB file (if self.handle is defined), maybe we should add a new utility method to the class to do this.

This comment has been minimized.

Copy link
@ajoubertza

ajoubertza Nov 6, 2020

Member

I notice an old bug here. We also should not delete self.db if the user passed in the name of the file. In that case they own the file. We should only do the close and unlink if we created the temporary file on line 255.

raise ValueError("multiple entries in devices_info pointing "
"to the same Tango class")
Expand All @@ -297,6 +299,7 @@ def __init__(self, devices_info, server_name=None, instance_name=None,

# Target and arguments
if class_list and device_list:
os.close(self.handle)
os.unlink(self.db)
raise ValueError("mixing HLAPI and classical API in devices_info "
"is not supported")
Expand Down

0 comments on commit 7d63b8e

Please sign in to comment.