#34746: High CPU/memory consumption when a 5XX is raised with large local 
variables
--------------------------------------+------------------------------------
     Reporter:  Rémi Dupré            |                    Owner:  (none)
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Error reporting       |                  Version:  4.2
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  1                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Natalia Bidart):

 After some experimentation following the suggested link to reprlib,
 perhaps something like this could be a good alternative? (it needs better
 code formatting, more reprlib limits sets and tests, of course)

 {{{
 #!diff
 --- a/django/views/debug.py
 +++ b/django/views/debug.py
 @@ -347,12 +347,17 @@ class ExceptionReporter:
              self.template_does_not_exist = True
              self.postmortem = self.exc_value.chain or [self.exc_value]

 +        import reprlib
 +        repr_instance = reprlib.Repr()
 +        repr_instance.maxstring = 5000
 +        repr_instance.maxlist = 1000
 +
          frames = self.get_traceback_frames()
          for i, frame in enumerate(frames):
              if "vars" in frame:
                  frame_vars = []
                  for k, v in frame["vars"]:
 -                    v = pprint(v)
 +                    v = repr_instance.repr(v)
                      # Trim large blobs of data
                      if len(v) > 4096:
                          v = "%s… <trimmed %d bytes string>" % (v[0:4096],
 len(v))
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34746#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701899d2ec7db-1435dccf-c6a6-45ab-babe-16399d4e9d84-000000%40eu-central-1.amazonses.com.

Reply via email to