You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if you want to get auto-reloading you need to configure an application and run it using a production-grade web server like Uvicorn and follow their directions on how to set up auto-reloading. It would be great if the reactpy.run function did that by default.
Proposed Actions
First, decide if we should pass a new DebugOptions object to the run function or simply use **kwargs. The former aligns with the configure interface, but the latter may help delineate between the two.
Add reload=True settings for the run function as well as BackendImplementation.create_development_app. It's possible that a reload_dirs parameter could make sense here as well, but if the interfaces for specifying what directories to watch varies significantly between the backends we might choose not to do that. It may also be worth adding a
Then, it's just a question of making this happen for each backend development server. Since the all the async frameworks run on Uvicorn, that should be fairly straightforward, for Flask/Tornado that will require some investigation.
asgiref contains a WsgiToAsgi converter. It would technically be less performant than a true WSGI server, but our run utility is for debug purposes only anyways.
I have a vague memory of having tried WsgiToAsgi and that the websocket implementation I used in Flask was problematic. The Flask websocket implementation changed at some point though so it may be worth looking into. I know it still uses gevent though so there may be some conflicts with the fact that WsgiToAsgi runs the WSGI server in a thread.
Somehow be able to point to an ASGI application that lives in that file
If you can solve that, you can write the app string ("the_entrypoint:the_app").
I wonder if if would be possible to solve both those problems with some frame trickery:
frominspectimportcurrentframedefrun():
frame=currentframe().f_backapp=frame.f_globals["the_app"] =create_development_app() # patch in the application to __main__entrypoint=frame.f_globals["__file__"] # get the path to the entrypoint fileifframe.f_globals["__name__"] =="__main__":
serve_development_app(app, entrypoint)
This is very hand-wavy, but hopefully it gets the idea across.
I have no idea how to do that ! Could you share a code ?
Currently, if you want to get auto-reloading you need to configure an application and run it using a production-grade web server like Uvicorn and follow their directions on how to set up auto-reloading
Activity
Archmonger commentedon May 24, 2023
I'd say it's easier to run every backend using Uvicorn, and rely on Uvicorn's auto reloader.
rmorshea commentedon May 24, 2023
Not all supported backends are async (e.g. flask/tornado). All the async ones can use the Uvicorn reloader though.
Archmonger commentedon May 24, 2023
asgirefcontains aWsgiToAsgiconverter. It would technically be less performant than a true WSGI server, but our run utility is for debug purposes only anyways.rmorshea commentedon May 24, 2023
I have a vague memory of having tried
WsgiToAsgiand that the websocket implementation I used in Flask was problematic. The Flask websocket implementation changed at some point though so it may be worth looking into. I know it still uses gevent though so there may be some conflicts with the fact thatWsgiToAsgiruns the WSGI server in a thread.Archmonger commentedon Jun 14, 2023
uvicornauto reloading does not work when using uvicorn's Python API.Unfortunately it only works through command line. Or more accurately,
uvicorn.Config(app=...)needs to be a string.rmorshea commentedon Jun 14, 2023
There are two problems we'd need to solve:
If you can solve that, you can write the app string (
"the_entrypoint:the_app").I wonder if if would be possible to solve both those problems with some frame trickery:
This is very hand-wavy, but hopefully it gets the idea across.
Archmonger commentedon Jun 14, 2023
Yep, I have a simpler solution that might involve changing our
BackendImplementationprotocol.I don't want to overload #1051 with that. Will do in a follow up PR.
dridk commentedon Sep 11, 2024
I have no idea how to do that ! Could you share a code ?
Fixed: All is here https://reactpy.dev/docs/guides/getting-started/running-reactpy.html?highlight=uvicorn
Archmonger commentedon Jan 25, 2025
Closed in favor of #1113