Reset Dang Django Stack on Gunicorn Timeout

I am trying to debug rare Django application freezes. So far, I have not been able to isolate the problem, this happens approximately once a day in production, and Gunicorn restarts the process with the message:

[CRITICAL] WORKER TIMEOUT

Is there a way to configure Django or Gunicorn to remove the stack trace of a process that is restarting?

+5
source share
3 answers

Try setting your Gunicorn magazine in more detail, maybe set it to INFOor DEBUG, which might shed more light on the magazine.

You can also take a look at Dog Slow, which will record slow requests. https://pypi.python.org/pypi/dogslow .

, Sentry: https://www.getsentry.com/welcome/.

, - , , , - ?

+5
-

. . - , , . , , /, .

, worker_abort (. ).

def worker_abort(worker):
    worker.log.info("worker received abort signal")
    import threading, sys, traceback
    id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
    code = []
    for threadId, stack in sys._current_frames().items():
        code.append("\n# Thread: %s(%d)" % (id2name.get(threadId,""), threadId))
        stack = traceback.extract_stack(stack)
        for filename, lineno, name, line in stack:
            code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
            if line:
                code.append("  %s" % (line.strip()))
    worker.log.debug("\n".join(code))

, SIGABRT. -. .

:

http://docs.gunicorn.org/en/stable/settings.html, https://github.com/benoitc/gunicorn/issues/1493, https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py

0

This will print a stack trace for the employee at the time of its destruction. You will need to create a gunicorn configuration file and paste the following function into it.

def worker_abort(worker):
    import traceback, io
    debug_info = io.StringIO()
    debug_info.write("Traceback at time of timeout:\n")
    traceback.print_stack(file=debug_info)
    worker.log.critical(debug_info.getvalue())

(I tested this only in Python 3. If you are using Python 2, you need to change ioto StringIO. See StringIO in Python3 )

0
source

All Articles