From 86f1dfc2bc8360aa1bc337435fcb6555e8ee28f6 Mon Sep 17 00:00:00 2001 From: Taha Jahangir Date: Thu, 27 Apr 2023 12:27:26 +0330 Subject: [PATCH] Better garbage-collection on exceptions in sync_to_async --- asgiref/sync.py | 1 + 1 file changed, 1 insertion(+) diff --git a/asgiref/sync.py b/asgiref/sync.py index f8b40936..aad0393c 100644 --- a/asgiref/sync.py +++ b/asgiref/sync.py @@ -481,6 +481,7 @@ def thread_handler(self, loop, source_task, exc_info, func, *args, **kwargs): else: self.launch_map[current_thread] = source_task parent_set = True + source_task = None # allow the task to be garbage-collected in case of exceptions # Run the function try: # If we have an exception, run the function inside the except block