question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature request] auto-load app when running the app, and auto-refresh when changing the code

See original GitHub issue

I have built a webapp which runs like so:

pywebio.start_server(app, port=8080, debug=True)

But when I run the code, it does not automatically open the app in the browser; I need to manually type the address in the browser and run it.

Also, when I change my code while the app is running, it does not auto-refresh the webpage, and I need to refresh it manually.

Is there a way to do these already? If not, it would be a nice thing to add.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
wang0618commented, Oct 3, 2021

Now, with the latest stable verion, you can use this decorator to make page refresh when the server restart:

import pywebio
from functools import wraps

def auto_refresh(app):
    @wraps(app)
    def inner():
        pywebio.session.run_js('WebIO._state.CurrentSession.on_session_close(()=>{setTimeout(()=>location.reload(), 1000)})')
        app()
        pywebio.session.hold()
    return inner

Usage of the decorator is:

@auto_refresh
def main():
    put_text('hello')

start_server(main, port=8080, debug=True)  # need to enable debug
0reactions
wang0618commented, Oct 3, 2021

You can pass auto_open_webbrowser=True to start_server() to enable auto open web browser when server is started

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to auto-reload files in Node.js?
--watch server Restart the app when changing .js , .mjs , .coffee , .litcoffee , and .json files in the server folder (included...
Read more >
Automatically refresh the browser on Node / Express server ...
After install, a simple working app can be seen just running npm start ... server doesn't even restart when we make changes in...
Read more >
Auto reload does not detect changes to index.js #9984
The auto refresh works fine as long as I keep editing App.js , but breaks down as soon as index.js is edited. Once...
Read more >
tornado.autoreload — Automatically detect code changes ...
tornado.autoreload — Automatically detect code changes in development¶. Automatically restart the server when a source file is modified.
Read more >
Autoloading and Reloading Constants
Rails automatically reloads classes and modules if application files in the autoload paths change. More precisely, if the web server is running and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found