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

Create mesop CLI to support Bazel-agnostic hot reload #60

Closed
4 tasks done
wwwillchen opened this issue Feb 23, 2024 · 0 comments
Closed
4 tasks done

Create mesop CLI to support Bazel-agnostic hot reload #60

wwwillchen opened this issue Feb 23, 2024 · 0 comments

Comments

@wwwillchen
Copy link
Collaborator

wwwillchen commented Feb 23, 2024

After supporting pip install mesop (#41), one of the issues with running Mesop on pip is that it doesn't support hot reload. Right now, Mesop's hot reload mechanism relies on ibazel which injects the livereload script and sends a rebuild event.

Questions:

  • How do we trigger a rebuild? Whenever an app file changes. This isn't going to be as good as ibazel where there's a proper dependency graph. We will do a simple heuristic if any file within a directory or sub-directory of the main module is changed, then we will reload everything. This is the same heuristic used inside
    def get_app_modules(
  • How do we send an event? Ideally, we will use websockets, otherwise we can do some sort of polling on the client-side.

Tasks:

Prior Art

Streamlit

Gradio

Home-grown

Basically create a while loop which checks file modified time.

    last_modified = os.path.getmtime(module_path)
    while True:
        # Get the current modification time
        current_modified = os.path.getmtime(module_path)

        # Compare the current modification time with the last modification time
        if current_modified != last_modified:
            # Update the last modification time
            last_modified = current_modified
            module = read_module(module_path)
            if module is not None:
                try:
                    runtime.set_module(module)
                    runtime.reload_all_sessions()
                except Exception as e:
                    runtime.log(
                        pb.ServerLog(
                            message=f"Hot reload error: Module '{module_path}' has {e}.\n${traceback.format_exc()}",
                            level=pb.ServerLog.ERROR,
                        )
                    )

        # Wait for 1 second before checking again
        await asyncio.sleep(1)
wwwillchen added a commit to wwwillchen/mesop that referenced this issue Feb 23, 2024
…pip (closes google#60)

Addresses a subtle race condition where hot reloading could happen in the middle of a request.
wwwillchen added a commit to wwwillchen/mesop that referenced this issue Apr 23, 2024
…pip (closes google#60)

Addresses a subtle race condition where hot reloading could happen in the middle of a request.
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

1 participant