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

RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'. #37

Closed whitphx closed 3 years ago

whitphx commented 3 years ago
File "/Users/whitphx/.pyenv/versions/3.8.6/envs/streamlit-dev/lib/python3.8/site-packages/streamlit/script_runner.py", line 332, in _run_script
    exec(code, module.__dict__)
File "/Users/whitphx/.ghq/github.com/whitphx/streamlit-webrtc/app.py", line 19, in <module>
    from aiortc.contrib.media import MediaPlayer
File "/Users/whitphx/.pyenv/versions/3.8.6/envs/streamlit-dev/lib/python3.8/site-packages/aiortc/__init__.py", line 8, in <module>
    from .rtcdtlstransport import (
File "/Users/whitphx/.pyenv/versions/3.8.6/envs/streamlit-dev/lib/python3.8/site-packages/aiortc/rtcdtlstransport.py", line 22, in <module>
    from .rtcicetransport import RTCIceTransport
File "/Users/whitphx/.pyenv/versions/3.8.6/envs/streamlit-dev/lib/python3.8/site-packages/aiortc/rtcicetransport.py", line 7, in <module>
    from aioice import Candidate, Connection
File "/Users/whitphx/.pyenv/versions/3.8.6/envs/streamlit-dev/lib/python3.8/site-packages/aioice/__init__.py", line 5, in <module>
    from .ice import Connection
File "/Users/whitphx/.pyenv/versions/3.8.6/envs/streamlit-dev/lib/python3.8/site-packages/aioice/ice.py", line 29, in <module>
    _mdns_lock = asyncio.Lock()
File "/Users/whitphx/.pyenv/versions/3.8.6/lib/python3.8/asyncio/locks.py", line 164, in __init__
    self._loop = events.get_event_loop()
File "/Users/whitphx/.pyenv/versions/3.8.6/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'

It seems this error occurs with aiortc >= 1.1.0 (aioice >= 0.7.2).

whitphx commented 3 years ago

This problem has been fixed in aioice==0.7.3

Defer mDNS lock initialisation to avoid mismatched event-loops, fixes errors seen with uvloop. https://github.com/aiortc/aioice/blob/main/docs/changelog.rst#073