Skip to content
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

debug reload no work #3459

Closed
tkzczen opened this issue Feb 14, 2025 · 5 comments
Closed

debug reload no work #3459

tkzczen opened this issue Feb 14, 2025 · 5 comments

Comments

@tkzczen
Copy link

tkzczen commented Feb 14, 2025

import asyncio
import tornado


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")


settings = {
    'template_path':'template',
    'static_path': 'static',
    'debug':True,
}

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
        (r"/run", MainHandler1),
    ],**settings)

async def main():
    app = make_app()
    app.listen(2022)
    await asyncio.Event().wait()

if __name__ == "__main__":
    asyncio.run(main())
@yelinaung
Copy link

@tkzczen Let's say if you add something like this

if __name__ == "__main__":
    import time
    print(f"Starting at {time.strftime('%X %x %Z')}")
    app = make_app()
    app.listen(2022)
    tornado.ioloop.IOLoop.current().start()

and you save the files a few times, do you see the timestamp change ? (example on my system)

❯ uv run app.py
Starting at 22:24:02 02/15/25 +08
Starting at 22:24:09 02/15/25 +08
Starting at 22:24:10 02/15/25 +08
Starting at 22:24:11 02/15/25 +08

@bdarnell
Copy link
Member

How exactly are you running this program? Which version of python, tornado, etc? The sample is incomplete (undefined reference to MainHandler1); is anything else missing?

@tkzczen
Copy link
Author

tkzczen commented Feb 18, 2025

How exactly are you running this program? Which version of python, tornado, etc? The sample is incomplete (undefined reference to MainHandler1); is anything else missing?

  • python 3.8.10
  • tornado 6.4.2

Before this , I used set settings = { 'debug':True}, The web server been auto restart the code when I change the web server code.But Now, I use asyncio and change web sever code,the sever not auto restart,every time I must close the program and run again.

@bdarnell
Copy link
Member

How exactly are you running it? Just python3 app.py? Something integrated into your editor? (Pycharm users have reported problems with autoreload, but since I don't use pycharm I don't know anything about that: #2243)

What platform? I'm not sure how well autoreload works on windows. Very old versions of MacOS used to have problems too but as far as I know that was fixed many years ago.

It's possible that you're hitting an error before the autoreload starts: If you use the code above you'll get an error for the undefined reference to MainHandler1, and because this is before the app is started with debug=True, it won't go into autoreload mode. To fix this, you need to use the autoreload command-line wrapper: python3 -m tornado.autoreload app.py.

@tkzczen
Copy link
Author

tkzczen commented Feb 19, 2025

How exactly are you running it? Just python3 app.py? Something integrated into your editor? (Pycharm users have reported problems with autoreload, but since I don't use pycharm I don't know anything about that: #2243)

What platform? I'm not sure how well autoreload works on windows. Very old versions of MacOS used to have problems too but as far as I know that was fixed many years ago.

It's possible that you're hitting an error before the autoreload starts: If you use the code above you'll get an error for the undefined reference to MainHandler1, and because this is before the app is started with debug=True, it won't go into autoreload mode. To fix this, you need to use the autoreload command-line wrapper: python3 -m tornado.autoreload app.py.

I found that the web did not restart due to a problem with my code. In my other code, it is not the same as the example above. I will modify it to tornado.web Application was set as a variable and then returned with a method, causing debug to not work. I modified the code and now the problem is solved. The original error code is as follows.

application = tornado.web.Application([
        (r"/", MainHandler),
        (r"/run", MainHandler1),
    ],**settings)
def make_app():
    return application

async def main():
    app = make_app()
    app.listen(2022)
    await asyncio.Event().wait()

There are no more issues now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants