do not crash when a conenction can not be done
This commit is contained in:
4
secop.py
4
secop.py
@ -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))
|
||||
|
||||
|
@ -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):
|
||||
|
Reference in New Issue
Block a user