diff --git a/asgiref/sync.py b/asgiref/sync.py index f8b40936..6ba55dc3 100644 --- a/asgiref/sync.py +++ b/asgiref/sync.py @@ -481,6 +481,9 @@ 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