question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebSocketClientFactory's _batched_timer SHOULD use the passed event loop

See original GitHub issue

Hey,

here’s my second issue report in a week:

The WebSocketClientFactory can be passed an event loop:

https://github.com/crossbario/autobahn-python/blob/bba4ed8418e59a678012ecb466092bee250b906f/autobahn/asyncio/websocket.py#L288-L289

… 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:open
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
meejahcommented, May 24, 2018

Oh, hrmmmmm, txaio master’s make_batched_timer doesn’t take a loop= 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 pass loop= to the websocket factory

1reaction
meejahcommented, May 23, 2018

(BTW, thanks for tracking this down and for a clear bug report!)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I integrate the WebSocketClient with an event loop?
I need to integrate the WebSocketClient with a different connection inside the same app. This would require the use of something like the ......
Read more >
Problems with event_loops in Python 3.10 - Stack Overflow
With python 3.9 as Interpreter it runs fine, but with 3.10 it gives me errors :( Here is the code: import asyncio from...
Read more >
Module autobahn.asyncio
IWebSocketClientChannelFactory() , you can supply a loop keyword argument to specify the asyncio event loop to be used. WAMP-over-WebSocket Protocols and ...
Read more >
Breaking down Node.js and WebSockets to understand the ...
The event loop is a very simple but important part of how Node.js works. It is a continuously looping process where the main...
Read more >
Writing WebSocket client applications - Web APIs | MDN
WebSocket client applications use the WebSocket API to communicate with WebSocket servers using the WebSocket protocol.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found