-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Using realtime.listen() in a separate thread #66
Comments
I'm interested in working on this. But I'm not sure where to start, I'm thinking of exposing the internal functions like I might be very off here, is there someone that I can talk to about the high level implementation on this? Maybe @silentworks have some insights? |
For my case, running realtime with existing web server (FastAPI) crashes because there's already event loop running managed by FastAPI.
The workaround for me is to use the async def start():
URL = f'wss://{os.getenv("SUPABASE_ID", "")}.supabase.co/realtime/v1/websocket?apikey={os.getenv("SUPABASE_SERVICE_ROLE_KEY", "")}&vsn=1.0.0'
s = Socket(URL)
# s.connect()
await s._connect()
channel_1 = cast(Channel, s.set_channel("realtime:storage:objects"))
# channel_1.join().on("UPDATE", reindex)
await asyncio.create_task(channel_1._join())
channel_1.on("UPDATE", reindex)
#s.listen()
asyncio.create_task(s._listen())
asyncio.create_task(s._keep_alive()) I wonder what the I tried replacing cc @J0 |
To solve this problem, you need to create and run an event loop inside the function, which will be executed in a separate thread. def socket_listen()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
s = Socket(URL)
s.connect()
channel_1 = s.set_channel("realtime:*")
s.listen() |
Hello,
Is it possible to use the realtime.listen() function in a separate thread?
All my trials have failed so far causing following exception:
raise RuntimeError('There is no current event loop in thread %r.'
at the line: loop = asyncio.get_event_loop() # TODO: replace with get_running_loop in connection.py
Cheers
The text was updated successfully, but these errors were encountered: