-
Notifications
You must be signed in to change notification settings - Fork 52
Description
When using the qasync event loop for an autobahn wamp component my CPU gets fully utilized. Using the default asyncio loop works fine. The following adapted autobahn example shows the problem (needs a wamp server like crossbar running):
from autobahn.asyncio.component import Component, run
from autobahn.wamp.types import RegisterOptions
from qasync import QEventLoop, asyncSlot, asyncClose
from PySide2.QtWidgets import QApplication
import asyncio, sys, logging
component = Component(
transports=[
{
"type": "websocket",
"url": "ws://localhost:8080/ws",
"endpoint": {
"type": "tcp",
"host": "localhost",
"port": 8080,
},
"options": {
"open_handshake_timeout": 100,
}
},
],
realm="crossbardemo",
)
@component.on_join
def join(session, details):
print("joined {}".format(details))
@component.register(
"example.foo",
options=RegisterOptions(details_arg='details'),
)
async def foo(*args, **kw):
print("foo({}, {})".format(args, kw))
for x in range(5, 0, -1):
print(" returning in {}".format(x))
await asyncio.sleep(1)
print("returning '42'")
return 42
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
app = QApplication(sys.argv)
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
asyncio.ensure_future(component.start())
sys.exit(asyncio.get_event_loop().run_forever())
The logger spams the following message when using QEventLoop:
DEBUG:qasync._unix._Selector:File 22 ready to write DEBUG:qasync._QEventLoop:Processing event with key SelectorKey(fileobj=22, fd=22, events=3, data=(<Handle _SelectorSocketTransport._read_ready()>, <Handle BaseSelectorEventLoop._sock_connect_cb(<Future finished result=None>, <socket.socke...0.0.1', 8000)>, ('127.0.0.1', 8000))>)) and mask 2 DEBUG:qasync._QEventLoop:Invoking writer callback: <Handle BaseSelectorEventLoop._sock_connect_cb(<Future finished result=None>, <socket.socke...0.0.1', 8000)>, ('127.0.0.1', 8000))>
I'm using:
Manajaro Linux
Qt & PySide 5.15.2
Python 3.9.1
autobahn 20.12.3 (installed via pip)
and qasync 0.13.0 (installed via pip)
Any ideas what the problem could be?