New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Reloader #85

Closed
loomchild opened this Issue Feb 18, 2015 · 6 comments

Comments

Projects
None yet
6 participants
@loomchild

I'd like to use Waitress both during development and in production (for simplicity, easier bugfixing, etc.). One little problem I have is that it does not support automatic module reloading when the code changes (like for example Werkzeug Reloader: http://werkzeug.pocoo.org/docs/0.10/serving/#reloader).

  1. Did I miss anything, is this feature supported? Is there already some discussion on this subject?
  2. If not then would it be a good idea to add such functionality to Waitress? Is providing development server in addition to production server within the scope of the project?
  3. If yes then would it be difficult / complex to add such functionality (if not then perhaps I could prepare a pull request)?
@bertjwregeer

This comment has been minimized.

Show comment
Hide comment
@bertjwregeer

bertjwregeer Feb 18, 2015

Member

Take a look at pserve from the Pyramid project, it adds a --reload on top of waitress to do exactly what you are looking to do. You may be able to easily port that and use it as a starting point.

Member

bertjwregeer commented Feb 18, 2015

Take a look at pserve from the Pyramid project, it adds a --reload on top of waitress to do exactly what you are looking to do. You may be able to easily port that and use it as a starting point.

@mmerickel

This comment has been minimized.

Show comment
Hide comment
@mmerickel

mmerickel Feb 18, 2015

Member

There is also https://pypi.python.org/pypi/ReloadWSGI. I don't think this functionality belongs in waitress itself as it has minimal idea what can change. It's basically only limited to tracking your wsgi app and not other assets.

Member

mmerickel commented Feb 18, 2015

There is also https://pypi.python.org/pypi/ReloadWSGI. I don't think this functionality belongs in waitress itself as it has minimal idea what can change. It's basically only limited to tracking your wsgi app and not other assets.

@mcdonc

This comment has been minimized.

Show comment
Hide comment
@mcdonc

mcdonc Feb 18, 2015

Member

I wouldn't be totally averse to seeing Waitress optionally kick off a thread that effectively restarted the server if any code it was serving changed. But, yeah, as @mmerickel said for better or worse, eventually people want a reloader "closer" to their application such that it can know about things that aren't pure-Python code like configuration files.

Member

mcdonc commented Feb 18, 2015

I wouldn't be totally averse to seeing Waitress optionally kick off a thread that effectively restarted the server if any code it was serving changed. But, yeah, as @mmerickel said for better or worse, eventually people want a reloader "closer" to their application such that it can know about things that aren't pure-Python code like configuration files.

@loomchild

This comment has been minimized.

Show comment
Hide comment
@loomchild

loomchild Feb 19, 2015

Thank you for your answers, they are very helpful.

@bertjwregeer: I would like to embed server inside my application, I don't know how to do it with pserve. Another thing is it requires me to add Pyramid web framework as a dependecy and use a specific configuration file, which I would like to avoid because I am already using different web framework (Flask). I will look into the code to see how --reload is implemented though.

@mmerickel: as far as I see ReloadWSGI depends on Python Paste and again I would like to avoid adding too many complex dependencies (this is one of the reasons I am using Waitress).

@mmerickel and @mcdonc: I think the most important thing to monitor is source code. Perhaps configuration files could be specified manually as a parameter.

Thank you for your answers, they are very helpful.

@bertjwregeer: I would like to embed server inside my application, I don't know how to do it with pserve. Another thing is it requires me to add Pyramid web framework as a dependecy and use a specific configuration file, which I would like to avoid because I am already using different web framework (Flask). I will look into the code to see how --reload is implemented though.

@mmerickel: as far as I see ReloadWSGI depends on Python Paste and again I would like to avoid adding too many complex dependencies (this is one of the reasons I am using Waitress).

@mmerickel and @mcdonc: I think the most important thing to monitor is source code. Perhaps configuration files could be specified manually as a parameter.

@tseaver tseaver added the enhancement label Feb 19, 2015

@loomchild

This comment has been minimized.

Show comment
Hide comment
@loomchild

loomchild Feb 22, 2015

All reloading solutions I came across work by spawning a child process (not thread!) with the same parameters as the main process, but with some special flag set to distinguish between them. There seems to be no other good way to reload all modules and perform necessary setup. This can be very confusing for user or programmer when the server is embedded inside the application, because any operation before entering main server loop (updating database, opening a file or displaying "Starting..." message) will be executed twice.

Now it seems much cleaner to me to use dedicated tool that will monitor the server process and restart it when necessary. One problem with generic utility is to know which files to monitor since there is no access to currently loaded Python modules. I think that for development purposes it should be sufficient to moitor main project directory ignoring frequently changing files. I found several utilities that can do that (inotifywatch, inotify-hooks, watchdog autoreload trick), but none of them is behaving exacly how I want, so will try to create a new simple one (work in progress, probably implemented using watchdog since it's multiplatform): https://github.com/loomchild/reload.

Thanks a lot for your help, if you agree then please close the ticket.

All reloading solutions I came across work by spawning a child process (not thread!) with the same parameters as the main process, but with some special flag set to distinguish between them. There seems to be no other good way to reload all modules and perform necessary setup. This can be very confusing for user or programmer when the server is embedded inside the application, because any operation before entering main server loop (updating database, opening a file or displaying "Starting..." message) will be executed twice.

Now it seems much cleaner to me to use dedicated tool that will monitor the server process and restart it when necessary. One problem with generic utility is to know which files to monitor since there is no access to currently loaded Python modules. I think that for development purposes it should be sufficient to moitor main project directory ignoring frequently changing files. I found several utilities that can do that (inotifywatch, inotify-hooks, watchdog autoreload trick), but none of them is behaving exacly how I want, so will try to create a new simple one (work in progress, probably implemented using watchdog since it's multiplatform): https://github.com/loomchild/reload.

Thanks a lot for your help, if you agree then please close the ticket.

@davisagli

This comment has been minimized.

Show comment
Hide comment
@davisagli

davisagli Apr 13, 2015

Member

Closing this since it sounds like you found another solution.

Member

davisagli commented Apr 13, 2015

Closing this since it sounds like you found another solution.

@davisagli davisagli closed this Apr 13, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment