I have a sanic application where I allow the user to pick the port they run sanic on.
I’m trying to figure out how to get something printed to the screen as a notification to the user if they’re trying to bind to a port that’s unavailable (something else is already listening on that port) or if they’re unauthorized (port is too low and they need to sudo).
Here’s the loops I’m working with:
if __name__ == "__main__": asyncio.set_event_loop(dbloop) if use_ssl: context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH) context.load_cert_chain(ssl_cert_path, keyfile=ssl_key_path) server = test.create_server(host=listen_ip, port=listen_port, ssl=context) else: server = test.create_server(host=listen_ip, port=listen_port, debug=False) loop = asyncio.get_event_loop() task = asyncio.ensure_future(server) db_objects.database.allow_sync = True try: loop.run_until_complete(test_db.connect_async(loop=dbloop)) loop.run_forever() except Exception as e: print(e) loop.stop()
Right now, if a user runs it and Sanic fails to bind to the port, they see nothing different than if it was successful.