Prevent CherryPy from automatically reloading
Asked Answered
C

1

11

It boggles my mind that this hasn't already been asked on Stack Overflow, but I gave it an honest search...

I'm currently developing a simple web application using CherryPy (and routes and Mako, in case its relevant.) This is going fine except for some very helpful mechanism CherryPy possesses that automatically reloads the server process whenever I change the code; inevitably, this will futz with my IDE's debugger, crash due to half-written code, and leave behind a dud process listening on the relevant port that causes later server processes to refuse to run until I manually force-quit it from the task manager.

From looking around, it sounded like this could be disabled via the config dictionary passed to CherryPy as it initializes, e.g.

conf = {'/': {'request.dispatch': d, 'engine.autoreload.on' : False}}

cherrypy.tree.mount(root=None, config=conf)

This doesn't seem to change anything, however. Is there something I'm missing here?

Checkrein answered 16/2, 2016 at 21:24 Comment(1)
Are you using quickstart? or engine.start/block?Caril
C
13

You have to configure the the autoreload on the global namespace because is part of the engine:

app_conf = {'/': {'request.dispatch': d}}
cherrypy.config.update({
    'global': {
       'engine.autoreload.on' : False
     }
 })
cherrypy.tree.mount(root=None, config=app_conf)

Or better yet set the production environment:

 cherrypy.config.update({
     'global': {
        'environment' : 'production'
      }
 })

Which will disable the autoreload among other things.

Caril answered 17/2, 2016 at 0:47 Comment(3)
This is the solution I eventually found, though I used just cherrypy.config.update({'engine.autoreload.on' : False}). Its confusing that cherrypy.config and the "config" parameter to cherrypy.tree.mount are apparently different things.Checkrein
cherrypy.config is a dict containing the server settings.Scrap
the config in cherrypy.tree.mount applies to the app you are mounting on that server.Scrap

© 2022 - 2024 — McMap. All rights reserved.