2 Commits

Author SHA1 Message Date
Shin'ichiro Kawasaki
9265086b12 Tag version 0.2.3
Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-05-08 21:04:03 +09:00
Shin'ichiro Kawasaki
58a60c94db scratch_link.py: Avoid eternal loop by hostname resolve failure
When the address of device-manager.scratch.mit.edu can not be resolved,
scratch_link.py catches the exception for the resolve failure and
restarts itself. This results in eternal loop.

To avoid the eternal loop, catch the resolve failure, print error
message and break the loop. Also improve the error message for the other
exceptions caught in the loop.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
2021-05-08 20:32:05 +09:00
3 changed files with 15 additions and 2 deletions

View File

@@ -202,6 +202,10 @@ Please file issues to [GitHub issue tracker](https://github.com/kawasaki/pyscrli
Releases Releases
-------- --------
Release 0.2.3
* Fixed eternal loop caused by hostname resolve failure
Release 0.2.2 Release 0.2.2
* Supported multiple device connections for toio * Supported multiple device connections for toio

View File

@@ -8,6 +8,7 @@ import asyncio
import pathlib import pathlib
import ssl import ssl
import websockets import websockets
import socket
import json import json
import base64 import base64
import logging import logging
@@ -42,6 +43,8 @@ logger.setLevel(logLevel)
logger.addHandler(handler) logger.addHandler(handler)
logger.propagate = False logger.propagate = False
HOSTNAME="device-manager.scratch.mit.edu"
class Session(): class Session():
"""Base class for BTSession and BLESession""" """Base class for BTSession and BLESession"""
def __init__(self, websocket, loop): def __init__(self, websocket, loop):
@@ -738,7 +741,7 @@ def main():
ssl_context.load_cert_chain(localhost_cer, localhost_key) ssl_context.load_cert_chain(localhost_cer, localhost_key)
start_server = websockets.serve( start_server = websockets.serve(
ws_handler, "device-manager.scratch.mit.edu", 20110, ssl=ssl_context ws_handler, HOSTNAME, 20110, ssl=ssl_context
) )
while True: while True:
@@ -749,7 +752,13 @@ def main():
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
stack_trace() stack_trace()
break break
except socket.gaierror as e:
logger.error(f"{type(e).__name__}: {e}")
logger.info(f"Check internet connection to {HOSTNAME}. If not "
f"available, add '127.0.0.1 {HOSTNAME}' to /etc/hosts.")
break
except Exception as e: except Exception as e:
logger.error(f"{type(e).__name__}: {e}")
logger.info("Restarting scratch-link...") logger.info("Restarting scratch-link...")
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools.setup( setuptools.setup(
name="pyscrlink", name="pyscrlink",
version="0.2.2", version="0.2.3",
author="Shin'ichiro Kawasaki", author="Shin'ichiro Kawasaki",
author_email='kawasaki@juno.dti.ne.jp', author_email='kawasaki@juno.dti.ne.jp',
description='Scratch-link for Linux with Python', description='Scratch-link for Linux with Python',