Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
fix: gc.collect() of dependent elements
Browse files Browse the repository at this point in the history
cycle-reference may exist between an element and a traceback
stored in SardanaValue or SardanaAttribute as a consequence of
getting sys.exc_info(). Keeping a list of dependent elements in the
scope of delete_element() makes it impossible to gc.collect() to
collect the cycled objects. Use has_dependent_elements() in order
to determine if there are dependent elements and then call the
gc.collect(). Also, do not call it conditionally only for the pseudo counters
but for any element type - the cycle may be created for between any
alement and a traceback.
  • Loading branch information
reszelaz committed Jul 22, 2021
1 parent 7f84584 commit 563e299
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/sardana/pool/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,12 @@ def delete_element(self, name):
elem = self.get_element(full_name=name)
except:
raise Exception("There is no element with name '%s'" % name)

# TODO: most probably due to some cycle-reference the psuedo counter
# objects are not being deleted when undefining them, as a workaround
# try to delete them with gc.collect()
dependent_elements = elem.get_dependent_elements()
for dependent_element in dependent_elements:
if dependent_element.get_type() == ElementType.PseudoCounter:
gc.collect()
break

# cycle-reference may exist between the element and a traceback
# stored in SardanaValue or SardanaAttribute as a consequence of
# getting sys.exc_info() - try to delete them with gc.collect()
if elem.has_dependent_elements():
gc.collect()

dependent_elements = elem.get_dependent_elements()
if len(dependent_elements) > 0:
Expand Down

0 comments on commit 563e299

Please sign in to comment.