crossbario / crossbario/autobahn-python

a Future constructor is missing the `loop` kwarg

Open
#747 20 comments 1 reaction 1 assignee View on GitHub

@meejah is already working on this.

Since Mar 9, 2021.

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

Description

There's a Future created by the _consume method of autobahn.asyncio.websocket.WebSocketAdapterProtocol.

It is not passing the loop kwarg, which leads to NotImplementedErrorwhen the implicit default 'global' loop is not being used. If I understand correctly.

I am guessing it's possible to reproduce this simply by creating a custom loop, rather than asking for the default via asyncio.get_event_loop(), and passing that to the connection factory.

I encountered the issue when creating what amounts to an autobahn websocket connection test using py.test (with help from the pytest-asyncio package that provides some useful asyncio testing fixtures). To repeat that, write a test function to make a websocket connection so that:

  • the test is decorated with the pytest.mark.asyncio decorator, with the forbid_global_loopparameter set to True)
  • the event_loop fixture is used for the test, and explicitly used as the loop passed to autobahn

So the 'stanza' for such a test becomes like this:

from pytest import mark

@mark.asyncio(forbid_global_loop=True)
async def test_ws_connect(event_loop):
   "some test that connects"
...

Then, upon connect, the NotImplementedError will be raised.

As for fixing the issue, the loop appears to be available in the protocol as self.transport._loop, and I can confirm that passing it as loopkwarg fixes the issue.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.