Why server is not detecting changes source code in my python project?

351 views Asked by At

I change the original file to add a new routing, but the changes don't work even if I restart the gunicorn server. What is the reason for this? Is it Git, Visual Code, my remote Linux, VirtualanEnv ... or what? I'm deeply confused

enter image description here

1

There are 1 answers

1
Vytas On BEST ANSWER

It is hard to what the reason is, as there are many "moving" parts (the IDE, Gunicorn, etc); but I cannot reproduce your issue.

Maybe the server was not reloaded or restarted, against your expectation, and you are simply still dealing with Gunicorn running old code? If you are sure you have restarted your debug server, then it should not matter; otherwise make sure to pass the --reload option, see also: gunicorn autoreload on source change.

As to the application itself, the following MRE works for me:

import falcon


class Contest:
    def on_get(self, req, resp, contest_id):
        resp.media = {
            'contest_id': contest_id,
            'uri_template': req.uri_template,
        }

    def on_get_ping(self, req, resp):
        resp.content_type = falcon.MEDIA_TEXT
        resp.text = 'PONG\n'


application = falcon.App()

contest = Contest()
application.add_route('/api/v1/ping', contest, suffix='ping')
application.add_route('/api/v1/member/contest/{contest_id:int}', contest)
application.add_route('/api/v1/member/contest/new/{contest_id:int}', contest)

When running with gunicorn --reload --access-logfile - test:application, I can even comment out routes or bring them back, save, and the changes are reflected in the application's behaviour.

Checking the end points in question:

$ curl http://localhost:8000/api/v1/ping
PONG
$ curl http://localhost:8000/api/v1/member/contest/1
{"contest_id": 1, "uri_template": "/api/v1/member/contest/{contest_id:int}"}
$ curl http://localhost:8000/api/v1/member/contest/new/2
{"contest_id": 2, "uri_template": "/api/v1/member/contest/new/{contest_id:int}"}