Forums

Slow reload for Flask app

Evening,

When I'm trying to reload my Flask app after changes it's gotten really slow.

The error message it kicks out in the server log is:

2018-04-29 22:44:12 Gracefully killing worker 1 (pid: 5)...
2018-04-29 22:44:12 Gracefully killing worker 2 (pid: 8)...
2018-04-29 22:44:12 Error in atexit._run_exitfuncs:
2018-04-29 22:44:12 Traceback (most recent call last):
2018-04-29 22:44:12   File "/usr/lib/python3.6/logging/__init__.py", line 1913, in shutdown
2018-04-29 22:44:12     h.flush()
2018-04-29 22:44:12   File "/usr/lib/python3.6/logging/__init__.py", line 970, in flush
2018-04-29 22:44:12     if self.stream and hasattr(self.stream, "flush"):
2018-04-29 22:44:12   File "/home/username/.virtualenvs/venvnameorders/lib/python3.6/site-packages/werkzeug/local.py", line 328, in __bool__
2018-04-29 22:44:12     return bool(self._get_current_object())
2018-04-29 22:44:12   File "/home/username/.virtualenvs/venvnameorders/lib/python3.6/site-packages/werkzeug/local.py", line 306, in _get_current_object
2018-04-29 22:44:12     return self.__local()
2018-04-29 22:44:12   File "/home/username/.virtualenvs/venvnameorders/lib/python3.6/site-packages/flask/logging.py", line 30, in wsgi_errors_stream
2018-04-29 22:44:12     return request.environ['wsgi.errors'] if request else sys.stderr
2018-04-29 22:44:12 KeyError: 'wsgi.errors'
2018-04-29 22:45:13 Sun Apr 29 22:45:13 2018 - worker 1 (pid: 5) is taking too much time to die...NO MERCY !!!
2018-04-29 22:45:13 Sun Apr 29 22:45:13 2018 - worker 2 (pid: 8) is taking too much time to die...NO MERCY !!!

Not sure how to debug this... Can anyone help?

Thanks.

that is certainly quite weird. the first thing to look at would be if you are using any libraries etc that say spin off processes/run a daemon etc.

Can you think of anything you are doing that might do that?

Can think of anything. Checked pip freeze for ideas and I can see anything. SQLAlchemy, maybe?

don't think that is it. Does your app have any endpoints that may take particularly long to run?

Nothing crazy, and they're all completing successfully (Example: quick Pillow image, upload to Google bucket, redirect to Flask endpoint works fine).

I was having a timeout issue with a pyMongo connection to mLab, but the restart was running slow well before then.

Is there any way to get details of processes running on the server? Would ps -aux work or would I need admin privileges?

(Posting from a different username after an earlier post recommended developers run as a 'teacher' on clients accounts - excellent feature!)

btw- which webapp is this for? If you don't want to disclose it in the forums, send us an email and we can follow up there. There is currently no easy way for you to get details of the webapp processes, but we can certainly check behind the scenes for you.

I am still inclined to believe there is a runaway thread/subprocess that isn't returning. Not sure. Also- is this an intermittent problem, or does it occur every time you reload? and does it occur a second time say if you reload now and reload in 1 minutes time afterwards?

Also do you see any other problems aside from that error message?

I am getting same error when i am trying to reload my app please help 409 code slow_startup_error

{ "status": "error", "error": "slow_startup_error" }

What is happening during your web app startup? Is your web app restarted after some time?