Closed madzohan closed 3 years ago
Ok I figured out the correct way of running coro using this commit https://github.com/crossbario/autobahn-python/commit/ac1dd18e80ded077c26e4be8f62cce06a37ecfeb
import asyncio
import logging
import signal
from contextlib import suppress
logger = logging.getLogger(__name__)
def main(coro):
loop = asyncio.get_event_loop()
async def nicely_exit(sig):
logger.info(f"Shutting down due to {sig}")
tasks = asyncio.all_tasks()
for task in tasks:
# Do not cancel the current task.
if task is not asyncio.current_task():
task.cancel()
def cancel_all_callback(fut):
try:
fut.result()
except asyncio.CancelledError:
logger.debug("All task cancelled")
except Exception as e:
logger.error("Error while shutting down: {exception}", exception=e)
finally:
loop.stop()
fut = asyncio.gather(*tasks)
fut.add_done_callback(cancel_all_callback)
loop.add_signal_handler(signal.SIGINT, lambda: asyncio.ensure_future(nicely_exit("SIGINT")))
loop.add_signal_handler(signal.SIGTERM, lambda: asyncio.ensure_future(nicely_exit("SIGTERM")))
with suppress(asyncio.exceptions.CancelledError):
loop.run_until_complete(coro)
Using python 3.9 Tried different ways but have not succeeded yet
running using code
coro code where I open the page and wait forever