Run component without monopolizing the event loop

I need to run a WAMP client component within a webserver (FastAPI).

All examples use the ‘run’ method to launch the component. However the run method will monopolize the event-loop as it is going to call ‘loop.run_forever’.

So currently I’m calling the ‘_run’ underneath directly from within a task but is that the proper way of doing it?


You’re using the Component API, right? In that case, there is the start() method, which is intended for your use-case. The run() method starts logging, start()s all the components, handles cleanup, etc … so if you’re already handling all that, the start() method should be the right approach.


However I tried the below for instance and I get an error in> attached to a different loop

import asyncio
from autobahn.asyncio.component import Component

async def amain():
    def joined(session, details):
        print("session ready")

    comp = Component(transports='ws://')
    comp.on('join', joined)

    fut = comp.start()
   await fut

if __name__ == '__main__':

Seems that the issue I reported above is solved by putting the import statements inside the amain function

This should fix the loop problems:
Will be in the next release.

1 Like

… and here you are:

1 Like