Skip to content

Commit ac5babe

Browse files
committed
Add a destructor to FormLink
`FormLink.__del__()` calls `close()`, just in case. It is still advisable to use the "with" statement.
1 parent bc91b14 commit ac5babe

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

form/formlink.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ def __init__(self, args=None, keep_log=False):
8484
self._loggingin = None
8585
self.open(args, keep_log)
8686

87+
def __del__(self):
88+
"""Destructor.
89+
90+
Free the connection to the FORM process if it still exists. Since in
91+
general when the destructor is called in the garbage collection is hard
92+
to be determined (and may not be called at all until the program
93+
finishes), it is advisable to use the "with" statement.
94+
"""
95+
# Ignore possible errors caused by subtle timing problems.
96+
try:
97+
self.close()
98+
except:
99+
pass
100+
87101
def __enter__(self):
88102
"""Enter the runtime context."""
89103
return self

0 commit comments

Comments
 (0)