Memory best usage

My dash app is throwing a memory errors like the ones below. Any best practice on how to minimize memory usage?

127.0.0.1 - - [18/Dec/2017 09:42:28] "POST /_dash-update-component HTTP/1.1" 500 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 58545)
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\__init__.py", line 284, in debug_application
    app_iter = self.app(environ, start_response)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\app.py", line 1997, in __call__
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\app.py", line 1985, in wsgi_app
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\app.py", line 1540, in handle_exception
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\app.py", line 1982, in wsgi_app
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\flask\app.py", line 1598, in dispatch_request
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\dash\dash.py", line 541, in dispatch
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\dash\dash.py", line 509, in add_context
  File "C:\Program Files (x86)\Python36-32\lib\json\__init__.py", line 238, in dumps
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\plotly\utils.py", line 136, in encode
  File "C:\Program Files (x86)\Python36-32\lib\json\encoder.py", line 199, in encode
  File "C:\Program Files (x86)\Python36-32\lib\json\encoder.py", line 257, in iterencode
MemoryError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\serving.py", line 209, in run_wsgi
    execute(self.server.app)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\serving.py", line 199, in execute
    for data in application_iter:
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\__init__.py", line 319, in debug_application
    secret=self.secret) \
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 360, in render_full
    'summary':          self.render_summary(include_title=False),
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 334, in render_summary
    frame.render()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 424, in render
    'lines':            self.render_line_context(),
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 428, in render_line_context
    before, current, after = self.get_context_lines()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 537, in get_context_lines
    before = self.sourcelines[self.lineno - context - 1:self.lineno - 1]
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\utils.py", line 73, in __get__
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 501, in sourcelines
    mode='rb')
MemoryError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\socketserver.py", line 317, in _handle_request_noblock
  File "C:\Program Files (x86)\Python36-32\lib\socketserver.py", line 348, in process_request
  File "C:\Program Files (x86)\Python36-32\lib\socketserver.py", line 361, in finish_request
  File "C:\Program Files (x86)\Python36-32\lib\socketserver.py", line 696, in __init__
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\serving.py", line 232, in handle
    rv = BaseHTTPRequestHandler.handle(self)
  File "C:\Program Files (x86)\Python36-32\lib\http\server.py", line 418, in handle
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\serving.py", line 267, in handle_one_request
    return self.run_wsgi()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\serving.py", line 226, in run_wsgi
    traceback.plaintext)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\utils.py", line 73, in __get__
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 380, in plaintext
    return u'\n'.join(self.generate_plaintext_traceback())
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 376, in generate_plaintext_traceback
    yield u'    ' + frame.current_line.strip()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 548, in current_line
    return self.sourcelines[self.lineno - 1]
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\utils.py", line 73, in __get__
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\werkzeug\debug\tbtools.py", line 501, in sourcelines
    mode='rb')
MemoryError
----------------------------------------

An out of memory error is likely associated with how you’re manipulating your own data structures rather than anything to do with Dash per se. When does the error occur? If it’s on app startup then perhaps you’re trying to load something that is just too big for your machine’s resources. If it’s while handling a callback then it could be to do with how you’re manipulating data structures which could be managed better.

1 Like