do not crash when a conenction can not be done

This commit is contained in:
l_samenv
2025-02-13 10:58:28 +01:00
parent 77af8c760e
commit 832252bbbb
2 changed files with 7 additions and 4 deletions

View File

@ -152,13 +152,13 @@ class ScanStream(UdpStream):
self.select_dict[sock.fileno()] = self
def send_fake_udp(uri, equipment_id='fake'):
def send_fake_udp(uri, device='fake'):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
msg = json.dumps({
'SECoP': 'for_other_node',
'uri': uri,
'equipment_id': equipment_id,
'device': device,
}, ensure_ascii=False, separators=(',', ':')).encode('utf-8')
sock.sendto(msg, ('255.255.255.255', SECOP_UDP_PORT))

View File

@ -263,8 +263,11 @@ class EventStream:
if not isinstance(stream, Stream):
for streamcls, uri, kwargs in stream.events():
if uri not in self.streams:
print('add stream', uri, kwargs)
self.streams[uri] = streamcls(uri, **kwargs)
try:
self.streams[uri] = streamcls(uri, **kwargs)
print('added stream', uri, kwargs)
except Exception as e:
print('can not connect to', uri, repr(e))
for name, stream in self.streams.items():
try:
if stream.get_events(events, maxevents):