crossbario / crossbario/autobahn-python

WebSocketClientFactory's _batched_timer SHOULD use the passed event loop

Open
#1,007 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-discussion
Dominant language
Python
Stars
2.5k
Forks
768
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in autobahn/asyncio/websocket.py around WebSocketClientFactory's event-loop initialization and compare it with autobahn/websocket/protocol.py around _batched_timer. Trace how autoPings select their loop, especially when the client runs in a separate thread. Done means the passed event loop is used and autoPings work without a main event loop.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.