WebSocketClientFactory's _batched_timer SHOULD use the passed event loop
See original GitHub issueHey,
here’s my second issue report in a week:
The WebSocketClientFactory
can be passed an event loop:
… and WebSocketClientFactory
’s _batched_timer
SHOULD use it, which it doesn’t now:
https://github.com/crossbario/autobahn-python/blob/bba4ed8418e59a678012ecb466092bee250b906f/autobahn/websocket/protocol.py#L3798-L3801
Why is this a problem? Because if someone doesn’t have a main event loop, autoPings won’t work. My application doesn’t have a main event loop, it only has an event loop in a separate thread, which I initialize later, along with the websocket client.
As far as I’ve seen, txaio
uses the main event loop, and the websocket client can’t be told to use other than the main initialized one.
Correct me if I’m wrong, but now I have to have an asynchronous main event loop, just to have autopings working?
I can override the event loop with my one from the thread I start later with:
from asyncio import BaseEventLoop, new_event_loop
from txaio.aio import config
from threading import Thread
class SomeThread(Thread):
def run(self):
self.loop = new_event_loop() # type: BaseEventLoop
config.loop = self.loop
But… really? I don’t think this would be a nice solution, it looks rather like a hack to me. Also it’s important in the case of this hack to override the loop earlier than initializing the websocket client, otherwise it will use the original event loop.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
Oh, hrmmmmm, txaio master’s
make_batched_timer
doesn’t take aloop=
kwarg…If you’re reading this because you ran into it: advice is to set your custom loop via
txaio.config.loop = my_loop
before you do any connections or listens and NOT passloop=
to the websocket factory(BTW, thanks for tracking this down and for a clear bug report!)