python-running-autobahnpython-asyncio-websocket-server-in-a-separate-subproce
can-an-asyncio-event-loop-run-in-the-background-without-suspending-the-python-in
Was trying to solve my issue with this two links above but i have not.
I have the following error : RuntimeError: There is no current event loop in thread 'Thread-1'.
Here the code sample (python 3):
from autobahn.asyncio.wamp import ApplicationSession from autobahn.asyncio.wamp import ApplicationRunner from asyncio import coroutine import time import threading class PoloniexWebsocket(ApplicationSession): def onConnect(self): self.join(self.config.realm) @coroutine def onJoin(self, details): def on_ticker(*args): print(args) try: yield from self.subscribe(on_ticker, 'ticker') except Exception as e: print("Could not subscribe to topic:", e) def poloniex_worker(): runner = ApplicationRunner("wss://api.poloniex.com:443", "realm1") runner.run(PoloniexWebsocket) def other_worker(): while True: print('Thank you') time.sleep(2) if __name__ == "__main__": polo_worker = threading.Thread(None, poloniex_worker, None, (), {}) thank_worker = threading.Thread(None, other_worker, None, (), {}) polo_worker.start() thank_worker.start() polo_worker.join() thank_worker.join() So, my final goal is to have 2 threads launched at the start. Only one need to use ApplicationSession and ApplicationRunner. Thank you.