widgetti / solara

A Pure Python, React-style Framework for Scaling Your Jupyter and Web Apps
https://solara.dev
MIT License
1.9k stars 140 forks source link

Deprecation warnings #171

Closed astrofrog closed 1 year ago

astrofrog commented 1 year ago

When using solara with Python 3.11 I am running into deprecation warnings regarding the use of currentThread and setDaemon. I am also running into another deprecation warning that I can't track down - when I run solara from pytest, and set the -W error:DeprecationWarning flag, the starlette server keeps closing down and re-opening:

INFO     solara.server.app:app.py:511 new virtual kernel: be4531c6-d2c2-4270-981c-446fa454504c
INFO     solara.server.fastapi:starlette.py:171 Solara kernel requested for session_id=37ab0f5a-a422-4c07-bc89-9f8a699e10ca connection_id=be4531c6-d2c2-4270-981c-446fa454504c
DEBUG    asyncio:selector_events.py:54 Using selector: KqueueSelector
INFO     solara.server.app:app.py:511 new virtual kernel: be4531c6-d2c2-4270-981c-446fa454504c
INFO     solara.server.fastapi:starlette.py:171 Solara kernel requested for session_id=37ab0f5a-a422-4c07-bc89-9f8a699e10ca connection_id=be4531c6-d2c2-4270-981c-446fa454504c
DEBUG    asyncio:selector_events.py:54 Using selector: KqueueSelector
INFO     solara.server.app:app.py:511 new virtual kernel: be4531c6-d2c2-4270-981c-446fa454504c
INFO     solara.server.fastapi:starlette.py:171 Solara kernel requested for session_id=37ab0f5a-a422-4c07-bc89-9f8a699e10ca connection_id=be4531c6-d2c2-4270-981c-446fa454504c
DEBUG    asyncio:selector_events.py:54 Using selector: KqueueSelector
INFO     solara.server.app:app.py:511 new virtual kernel: be4531c6-d2c2-4270-981c-446fa454504c
INFO     solara.server.fastapi:starlette.py:171 Solara kernel requested for session_id=37ab0f5a-a422-4c07-bc89-9f8a699e10ca connection_id=be4531c6-d2c2-4270-981c-446fa454504c
DEBUG    asyncio:selector_events.py:54 Using selector: KqueueSelector

and the test hangs. This suggests there is a deprecation warning being emitted during the server startup but I couldn't track it down.

maartenbreddels commented 1 year ago

The currentThread / setDaemon issue is fixed in 6205d21308bc2e41c533bb4a514090059f6c750d If you have more information on how I can reproduce the other issue, please let me know here.

astrofrog commented 1 year ago

To reproduce the issues I'm seeing, you can take the pytest example straight from the docs:

import ipywidgets as widgets
import playwright.sync_api
from IPython.display import display

def test_widget_button_solara(solara_test, page_session: playwright.sync_api.Page):
    # this all runs in process, which only works with solara
    # also, this test is only with pure ipywidgets
    button = widgets.Button(description="Click Me!")

    def change_description(obj):
        button.description = "Tested event"

    button.on_click(change_description)
    display(button)
    button_sel = page_session.locator("text=Click Me!")
    button_sel.wait_for()
    button_sel.click()
    page_session.locator("text=Tested event").wait_for()

and put it in a file called e.g. test_example.py then run:

pytest test_example.py --headed -W error::DeprecationWarning

Currently this errors with:

DeprecationWarning: currentThread() is deprecated, use current_thread() instead

If you ignore this warning specifically you can get a bit further:

pytest test_example.py --headed -W error::DeprecationWarning -W ignore:currentThread

but then the window that pops up flashes in a loop and keeps saying 'Server disconnected' so clearly a deprecation warning is happening which is getting turned into an error when the server starts up

maartenbreddels commented 1 year ago

There is still something in Reacton using something deprecated, but https://github.com/widgetti/solara/commit/73024937b2ffc49f3b2225f8b9145c7a4e6221b3 and https://github.com/widgetti/solara/commit/b632d4fbc214793f8d6f7636155d321e962db4fb should fix this