Webhooks icon indicating copy to clipboard operation
Webhooks copied to clipboard

How to get autoreload work

Open kellytrinh opened this issue 5 years ago • 3 comments

Hi Todd,

Found your package when google searching for a simple webhook server. Its great - simple for a beginner at python like me.

Could I get some help tho - I see there is a 'autoreload' and it suggests that I can edit the source code and have the changes reflect on the server immediately (that's great for developing/debugging).

However, it does not seem to be working. When I set logScreen and autoReload to true; I get the output below. It seems to suggest that the file change notification is received but after the webserver is shutdown; it doesn't come back up again.

Am I missing a step?

[15/Jul/2020:12:37:18] ENGINE Bus STARTING
Still alive...
[15/Jul/2020:12:37:18] ENGINE Started monitor thread 'Autoreloader'.
[15/Jul/2020:12:37:18] ENGINE Serving on http://0.0.0.0:8090
[15/Jul/2020:12:37:18] ENGINE Bus STARTED
Received request:
[[[details of request elided ]]]
192.168.0.100 - - [15/Jul/2020:12:37:19] "POST /webhook-serrer HTTP/1.1" 200 2 "" "curl/7.58.0"
[15/Jul/2020:12:37:26] ENGINE Restarting because /home/kelly/system/testing/webserver.py changed.
[15/Jul/2020:12:37:26] ENGINE Stopped thread 'Autoreloader'.
[15/Jul/2020:12:37:26] ENGINE Bus STOPPING
[15/Jul/2020:12:37:26] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('0.0.0.0', 8090)) shut down
[15/Jul/2020:12:37:26] ENGINE Bus STOPPED
[15/Jul/2020:12:37:26] ENGINE Bus EXITING
[15/Jul/2020:12:37:26] ENGINE Bus EXITED
Still alive...

kellytrinh avatar Jul 15 '20 04:07 kellytrinh

Believe it or not, I have actually never tried to use the autoReload option. I will try to dig into this. Sorry it's taken so long even to respond.

toddrob99 avatar Jul 26 '20 12:07 toddrob99

No problem; take your time; it is kind enough you share with everyone to make use of...

kellytrinh avatar Jul 26 '20 14:07 kellytrinh

I tried to reproduce the issue, and I don't even get the log entry from cherrypy that it's restarting the engine. I am testing with example.py that's included in this repository. I added autoReload=True to line 80:

webhooks = webhook_listener.Listener(port=port, handlers={"POST": parse_request}, autoReload=True)

Then ran the script with the -v argument and sent a POST request. I saw the request in the log.

I then made a change to example.py (added a log entry at line 74: logger.debug("test")). There was no log entry written about the cherrypy engine restarting or exiting. I sent another POST request, which failed with a "connection refused" error, presumably because, although I didn't get the log entries, the cherrypy engine exited like you are seeing.

The only code related to cherrypy auto-reload is to first accept the keyword argument when creating the Listener instance on line 23:

self.autoReload = kwargs.get("autoReload", False)

and then to pass that value in to the cherrypy engine on line 43:

"engine.autoreload.on": self.autoReload,

I don't think there's much I can do to fix this behavior (I am not an expert with the cherrypy engine), but if anyone else would like to give it a shot, feel free to submit a pull request. Also note that autoReload should only be used during testing, so I do not consider this to be a critical feature.

toddrob99 avatar Jul 26 '20 17:07 toddrob99