Files
edx-platform/openedx/core/djangoapps/util/signals.py
Feanil Patel 9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00

35 lines
861 B
Python

"""
Signal handler for exceptions.
"""
# pylint: disable=unused-argument
import logging
from celery.signals import task_postrun
from django.conf import settings
from django.core.signals import got_request_exception
from django.dispatch import receiver
from edx_django_utils.cache import RequestCache
@receiver(got_request_exception)
def record_request_exception(sender, **kwargs):
"""
Logs the stack trace whenever an exception
occurs in processing a request.
"""
logging.exception(u"Uncaught exception from {sender}".format(
sender=sender
))
@task_postrun.connect
def _clear_request_cache(**kwargs):
"""
Once a celery task completes, clear the request cache to
prevent memory leaks.
"""
if getattr(settings, 'CLEAR_REQUEST_CACHE_ON_TASK_COMPLETION', True):
RequestCache.clear_all_namespaces()