whitphx / streamlit-webrtc

Real-time video and audio processing on Streamlit
https://discuss.streamlit.io/t/new-component-streamlit-webrtc-a-new-way-to-deal-with-real-time-media-streams/8669
MIT License
1.36k stars 182 forks source link

ReferenceError: weakly-referenced object no longer exists #1046

Closed creeksflowing closed 2 years ago

creeksflowing commented 2 years ago

Updated to 0.43.3 but I still get the same error on Mac M1 Pro

whitphx commented 2 years ago

Thank you for the report. Can you provide the details that I can use to reproduce the problem including

creeksflowing commented 2 years ago
  • Source code The source is from your example code (app.py). I tried running your examples for seeing if the new version worked.

  • Python version (and installation method if necessary, for example if you install it with some special way e.g. pyenv or with special compile option) The Python version is 3.10.6, installed in a venv with the built-in venv module.

  • Any other info if necessay This are the currently installed modules: aioice 0.7.6 aiortc 1.3.2 altair 4.2.0 attrs 22.1.0 av 9.2.0 blinker 1.5 cachetools 5.2.0 certifi 2022.6.15 cffi 1.15.1 charset-normalizer 2.1.1 click 8.1.3 commonmark 0.9.1 cryptography 37.0.4 cycler 0.11.0 decorator 5.1.1 dnspython 2.2.1 entrypoints 0.4 fonttools 4.37.1 gitdb 4.0.9 GitPython 3.1.27 google-crc32c 1.3.0 idna 3.3 importlib-metadata 4.12.0 Jinja2 3.1.2 jsonschema 4.15.0 kiwisolver 1.4.4 MarkupSafe 2.1.1 matplotlib 3.5.3 netifaces 0.11.0 numpy 1.23.2 opencv-python-headless 4.6.0.66 packaging 21.3 pandas 1.4.4 Pillow 9.2.0 pip 22.2.2 pip-review 1.2.0 protobuf 4.21.5 pyarrow 9.0.0 pycparser 2.21 pydeck 0.8.0b1 pydub 0.25.1 pyee 9.0.4 Pygments 2.13.0 pylibsrtp 0.7.1 Pympler 1.0.1 pyparsing 3.0.9 pyrsistent 0.18.1 python-dateutil 2.8.2 pytz 2022.2.1 pytz-deprecation-shim 0.1.0.post0 requests 2.28.1 rich 12.5.1 semver 2.13.0 setuptools 65.3.0 six 1.16.0 smmap 5.0.0 streamlit 1.12.2 streamlit-webrtc 0.43.3 toml 0.10.2 toolz 0.12.0 tornado 6.2 typing_extensions 4.3.0 tzdata 2022.2 tzlocal 4.2 urllib3 1.26.12 validators 0.20.0 zipp 3.8.1

dotchang commented 2 years ago

I got same error on Windows10 Anaconda (Python 3.9) environment. I just tried to run the chat example, $ pip install streamlit streamlit-webrtc streamlit-server-state opencv-python-headless $ streamlit run https://raw.githubusercontent.com/whitphx/streamlit-video-chat-example/main/app_mcu_filters.py

Best regards,

whitphx commented 2 years ago

Thank you for the report! I'm sorry but I could not reproduce the problem in my env (M1 mac, Python 3.10.6 (venv), the packages are installed as you listed).

Can you paste the entire error log and stack trace that you capture in your environment again?

creeksflowing commented 2 years ago

Thank you for the report! I'm sorry but I could not reproduce the problem in my env (M1 mac, Python 3.10.6 (venv), the packages are installed as you listed).

Can you paste the entire error log and stack trace that you capture in your environment again?

This is everything that appears on the terminal after running the app.py file with the streamlit run command:

[2022-09-03 15:51:21,057]   DEBUG from streamlit_webrtc.server in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/server.py:43: The running Streamlit version is gte 1.12.0. Try to get the server instance
2022-09-03 15:51:21.069 Uncaught app exception
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 556, in _run_script
    exec(code, module.__dict__)
  File "/Users/ettorecarlessi/Desktop/my_project/app.py", line 347, in <module>
    main()
  File "/Users/ettorecarlessi/Desktop/my_project/app.py", line 58, in main
    page_func()
  File "/Users/ettorecarlessi/Desktop/my_project/app.py", line 70, in app_sendonly_audio
    webrtc_ctx = webrtc_streamer(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/component.py", line 514, in webrtc_streamer
    session_info = get_this_session_info()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/session_info.py", line 43, in get_this_session_info
    current_server = get_current_server()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/server.py", line 52, in get_current_server
    servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)]
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/server.py", line 52, in <listcomp>
    servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)]
ReferenceError: weakly-referenced object no longer exists
[2022-09-03 15:51:21,323]   DEBUG from streamlit_webrtc.server in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/server.py:43: The running Streamlit version is gte 1.12.0. Try to get the server instance
2022-09-03 15:51:21.328 Uncaught app exception
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 556, in _run_script
    exec(code, module.__dict__)
  File "/Users/ettorecarlessi/Desktop/my_project/app.py", line 347, in <module>
    main()
  File "/Users/ettorecarlessi/Desktop/my_project/app.py", line 58, in main
    page_func()
  File "/Users/ettorecarlessi/Desktop/my_project/app.py", line 70, in app_sendonly_audio
    webrtc_ctx = webrtc_streamer(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/component.py", line 514, in webrtc_streamer
    session_info = get_this_session_info()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/session_info.py", line 43, in get_this_session_info
    current_server = get_current_server()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/server.py", line 52, in get_current_server
    servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)]
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/streamlit_webrtc/server.py", line 52, in <listcomp>
    servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)]
ReferenceError: weakly-referenced object no longer exists
whitphx commented 2 years ago

Thank you, it looks like an older version is used in your environment somehow.

The following code that appears in the stack trace has been removed in 0.43.3 (BTW, another bug was in v0.43.3, so please 0.43.4 now).

servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)]

Can you check the version of actually loaded streamlit-webrtc with, for example, the code below?

import streamlit_webrtc
print(streamlit_webrtc.__version__)
dotchang commented 2 years ago

Thank you for your reply. This is also an error report on clean installed Anaconda(most major version 3.9), Windows 10.

The executed commands are only

  1. pip install -U pip --user
  2. pip install streamlit streamlit-webrtc streamlit-server-state opencv-python-headless
  3. streamlit run https://raw.githubusercontent.com/whitphx/streamlit-video-chat-example/main/app_mcu_filters.py

The errors are

`(base) C:\Users\dotch>streamlit run https://raw.githubusercontent.com/whitphx/streamlit-video-chat-example/main/app_mcu_filters.py 2022-09-03 23:08:20.481 INFO numexpr.utils: NumExpr defaulting to 8 threads.

You can now view your Streamlit app in your browser.

Local URL: http://localhost:8501 Network URL: http://192.168.179.14:8501

2022-09-03 23:08:27.088 Uncaught app exception Traceback (most recent call last): File "C:\Users\dotch\anaconda3\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 556, in _run_script exec(code, module.dict) File "C:\Users\dotch\AppData\Local\Temp\tmp2b7_8jip\app_mcu_filters.py", line 16, in from streamlit_server_state import server_state, server_state_lock File "C:\Users\dotch\anaconda3\lib\site-packages\streamlit_server_state__init__.py", line 16, in _server = get_current_server() File "C:\Users\dotch\anaconda3\lib\site-packages\streamlit_server_state\server.py", line 52, in get_current_server servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)] File "C:\Users\dotch\anaconda3\lib\site-packages\streamlit_server_state\server.py", line 52, in servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)] ReferenceError: weakly-referenced object no longer exists`

I'll appreciate if you give us hints for solution. Best regards,

p.s. the version of streamlit-webrtc was 0.43.3. Python 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information.

import streamlit_webrtc 2022-09-03 23:19:47.497 INFO numexpr.utils: NumExpr defaulting to 8 threads. print(streamlit_webrtc.version) 0.43.3

dotchang commented 2 years ago

I am sorry my verbose reports. After reading your reply to creeksflowing, I tried to update the libraries and they are successfully installed. streamlit-1.12.2 streamlit-webrtc-0.43.4 (by pip install git+https://github.com/whitphx/streamlit-webrtc.git, thanks a lot.) streamlit-server-state-0.14.1

But unfortunately, still I have errors.

`(base) C:\Users\dotch>streamlit run https://raw.githubusercontent.com/whitphx/streamlit-video-chat-example/main/app_mcu_filters.py 2022-09-03 23:37:23.384 INFO numexpr.utils: NumExpr defaulting to 8 threads.

You can now view your Streamlit app in your browser.

Local URL: http://localhost:8501 Network URL: http://192.168.179.14:8501

2022-09-03 23:37:29.781 Uncaught app exception Traceback (most recent call last): File "C:\Users\dotch\anaconda3\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 556, in _run_script exec(code, module.dict) File "C:\Users\dotch\AppData\Local\Temp\tmpgej4fun7\app_mcu_filters.py", line 16, in from streamlit_server_state import server_state, server_state_lock File "C:\Users\dotch\anaconda3\lib\site-packages\streamlit_server_state__init__.py", line 16, in _server = get_current_server() File "C:\Users\dotch\anaconda3\lib\site-packages\streamlit_server_state\server.py", line 52, in get_current_server servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)] File "C:\Users\dotch\anaconda3\lib\site-packages\streamlit_server_state\server.py", line 52, in servers = [obj for obj in gc.get_objects() if isinstance(obj, Server)] ReferenceError: weakly-referenced object no longer exists`

Best,

whitphx commented 2 years ago

Oh, the error reported at the previous post caused in streamlit-server-state, not streamlit-webrtc.

dotchang commented 2 years ago

Thank you for the update, and I apologize the confusion about the streamlit-webrtc and the streamlit-server-satate. I misunderstood the streamlit-server-state is a part of streamlit-webrtc.

I could run the app_sfu_filter.py and app_sfu_simple.py successfully. (Maybe, because I just run them by only one instance. Still I could not get how to connect to another PC, but this is different topic here.) And I got another error that is missing MixerBase on the app_mcu_filter.py and app_mcu_simple.py.

`(base) c:\workspace\streamlit-video-chat-example>streamlit run app_mcu_simple.py 2022-09-04 02:43:26.108 INFO numexpr.utils: NumExpr defaulting to 8 threads.

You can now view your Streamlit app in your browser.

Local URL: http://localhost:8502 Network URL: http://192.168.179.14:8502

2022-09-04 02:43:32.784 Uncaught app exception Traceback (most recent call last): File "C:\Users\dotch\anaconda3\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 556, in _run_script exec(code, module.dict) File "C:\workspace\streamlit-video-chat-example\app_mcu_simple.py", line 9, in from streamlit_webrtc import ( ImportError: cannot import name 'MixerBase' from 'streamlit_webrtc' (C:\Users\dotch\anaconda3\lib\site-packages\streamlit_webrtc__init__.py)`

I know this is not topic of here. I will report the problem at https://github.com/whitphx/streamlit-video-chat-example.

Anyway thank you, thank you very much.

whitphx commented 2 years ago

And I got another error that is missing MixerBase on the app_mcu_filter.py and app_mcu_simple.py.

I see. That is another error rooted at the implementation of the video chat app itself. Sorry but that repository is outdated and not compatible with the latest version of streamlit-webrtc. Please be patient until it is updated. -> Fixed. The current HEAD should work.

creeksflowing commented 2 years ago

Hi! So, I tried upgrading through pip but for some reason it didn't work, so I made a fresh venv and resintalled everything and now it works like a charm! Thank you very much!