Skip to content

Commit

Permalink
Make Local instances clearable (without deleting)
Browse files Browse the repository at this point in the history
  • Loading branch information
ababic committed Apr 19, 2023
1 parent 30d891f commit 5c612c4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion asgiref/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _get_storage(self):
self._context_refs.add(context_obj)
return getattr(context_obj, self._attr_name)

def __del__(self):
def clear(self):
try:
for context_obj in self._context_refs:
try:
Expand All @@ -96,6 +96,9 @@ def __del__(self):
# to _IterationGuard being None.
pass

def __del__(self):
self.clear()

def __getattr__(self, key):
with self._thread_lock:
storage = self._get_storage()
Expand Down

0 comments on commit 5c612c4

Please sign in to comment.