From a55f04dc288466c3d07c088f907f7be7bf52178d Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 19 Mar 2020 22:36:55 +0200 Subject: [PATCH] Warn that can't allocate socket for PIO Home --- platformio/commands/home/command.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/platformio/commands/home/command.py b/platformio/commands/home/command.py index 208354bf..229c875e 100644 --- a/platformio/commands/home/command.py +++ b/platformio/commands/home/command.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=too-many-locals +# pylint: disable=too-many-locals,too-many-statements import mimetypes import socket @@ -63,6 +63,7 @@ def cli(port, host, no_open, shutdown_timeout): from twisted.internet import reactor from twisted.web import server + from twisted.internet.error import CannotListenError from platformio.commands.home.rpc.handlers.app import AppRPC from platformio.commands.home.rpc.handlers.ide import IDERPC @@ -121,6 +122,12 @@ def cli(port, host, no_open, shutdown_timeout): click.echo("") click.echo("Open PlatformIO Home in your browser by this URL => %s" % home_url) + try: + reactor.listenTCP(port, site, interface=host) + except CannotListenError as e: + click.secho(str(e), fg="red", err=True) + already_started = True + if already_started: click.secho( "PlatformIO Home server is already started in another process.", fg="yellow" @@ -129,7 +136,6 @@ def cli(port, host, no_open, shutdown_timeout): click.echo("PIO Home has been started. Press Ctrl+C to shutdown.") - reactor.listenTCP(port, site, interface=host) reactor.run()