Pyramid + uwsgi auto reload on source change

608 views
Skip to first unread message

Srikanth Bemineni

unread,
Jan 11, 2016, 12:39:49 AM1/11/16
to pylons-discuss


Hi ,

Is there way we can make uwsgi reload on src change during development. I am looking for similar behaviour as pserve development.ini --reload

I found a django.utils. which detects file change, and we can initiate a uwsgi reload. Is there something similar in pyramid.

import uwsgi
from uwsgidecorators import timer
from django.utils import autoreload

@timer(3)
def change_code_gracefull_reload(sig):
    if autoreload.code_changed():
        uwsgi.reload()



Srikanth Bemineni

Jason

unread,
Jan 12, 2016, 6:22:24 PM1/12/16
to pylons-discuss

On Sunday, January 10, 2016 at 7:39:49 PM UTC-5, Srikanth Bemineni wrote:


Hi ,

Is there way we can make uwsgi reload on src change during development. I am looking for similar behaviour as pserve development.ini --reload



This doesn't answer your question, but I would recommend using pserve and waitress for development. Although you should keep your development environment as similar as possible to production, the ease of not installing/configuring uWSGI on the development machine trumps the consistency of environment. I've found that the during development there are very rarely changes any of the uwsgi server configuration and it's much faster to get setup if you don't have the dependency on uWSGI.

-- Jason

Jonathan Vanasco

unread,
Jan 12, 2016, 6:43:16 PM1/12/16
to pylons-discuss


On Tuesday, January 12, 2016 at 1:22:24 PM UTC-5, Jason wrote:

This doesn't answer your question, but I would recommend using pserve and waitress for development.

We use nginx>uwsgi in production and nginx>pserve in development.  By keeping nginx consistent, it really minimized the differences between the two environments.  

There are still some differences, there are separate includes for each environment under nginx and uwsgi integrates differently than proxy-pass... but the deployments are similar enough that this works incredibly well.

tldr; use Jason's advice but you can also front port-80 with the same proxy/gateway/webserver in dev as you do in production.

Srikanth Bemineni

unread,
Jan 14, 2016, 11:55:10 PM1/14/16
to pylons-discuss

Hi,

I am currently using pserve for development. But this is making me do some changes to code when I move from development to production or vice versa. In my main app init.py I use the below imports

from uwsgidecorators import postfork

This is needed for initiating my cassandra connections on forking. uwsgidecorator imports uwsgi, which will be only available when I run using uwsgi. So when I start development from fresh checked out code. I need to comment these lines.

I also feel like using pserve will not allow me to test any forking issue that may be seen during production, where I am thinking of using nginx + uwsgi.

Srikanth

Bert JW Regeer

unread,
Jan 15, 2016, 12:27:23 AM1/15/16
to pylons-...@googlegroups.com
http://uwsgi-docs.readthedocs.org/en/latest/HTTP.html
http://uwsgi-docs.readthedocs.org/en/latest/articles/TheArtOfGracefulReloading.html

And then there is:
http://uwsgi-docs.readthedocs.org/en/latest/Options.html#py-autoreload

Mix and match, should get you to uWSGI being an HTTP server that you can hit.

Bert
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
> To post to this group, send email to pylons-...@googlegroups.com.
> Visit this group at https://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.

Bert JW Regeer

unread,
Jan 15, 2016, 12:28:14 AM1/15/16
to pylons-...@googlegroups.com
http://chase-seibert.github.io/blog/2014/03/30/uwsgi-python-reload.html

A blog post that details some of this.

Bert

> On Jan 14, 2016, at 16:55, Srikanth Bemineni <bemineni...@gmail.com> wrote:
>
>

Jonathan Vanasco

unread,
Jan 15, 2016, 5:25:41 PM1/15/16
to pylons-discuss


On Thursday, January 14, 2016 at 6:55:10 PM UTC-5, Srikanth Bemineni wrote:
from uwsgidecorators import postfork

This is needed for initiating my cassandra connections on forking. uwsgidecorator imports uwsgi, which will be only available when I run using uwsgi. So when I start development from fresh checked out code. I need to comment these lines.

You can usually handle stuff like that where you have a `config` available, or use environment variables / a custom namespace.  then you conditionally do the imports and handle the atfork.

otherwise, i think you might get better performance by using waitress and manually starting/stopping a local uwsgi server when you want to test on that particular platform.

i do 99% of my testing on nginx->waitress, but can also toggle nginx->uwsgi for a few specific tests (such as the atfork stuff).
Reply all
Reply to author
Forward
0 new messages