feeder: use FrappyManager to connect to running frappy instances
This commit is contained in:
21
streams.py
21
streams.py
@ -23,7 +23,14 @@ INF = float('inf')
|
||||
|
||||
|
||||
class Base:
|
||||
select_dict = {}
|
||||
select_read = {}
|
||||
select_write = {}
|
||||
|
||||
def close(self):
|
||||
print('CLOSE BASE')
|
||||
|
||||
def finish_events(self, *args):
|
||||
print('FINISH BASE')
|
||||
|
||||
|
||||
def short_hostname(host):
|
||||
@ -67,12 +74,12 @@ class Stream(Base):
|
||||
self.connect()
|
||||
self.init(**kwds)
|
||||
except Exception as e:
|
||||
print(self.uri, repr(e))
|
||||
print('I', self.uri, repr(e))
|
||||
raise
|
||||
|
||||
def connect(self):
|
||||
self.socket = socket.create_connection(parse_uri(self.uri))
|
||||
self.select_dict[self.socket.fileno()] = self
|
||||
self.select_read[self.socket.fileno()] = self
|
||||
self.settimeout(self.timeout)
|
||||
host, _, port = self.uri.partition(':')
|
||||
# try to convert uri to host name
|
||||
@ -96,7 +103,7 @@ class Stream(Base):
|
||||
"""Do our best to close a socket."""
|
||||
if self.socket is None:
|
||||
return
|
||||
self.select_dict.pop(self.socket.fileno(), None)
|
||||
self.select_read.pop(self.socket.fileno(), None)
|
||||
print(self.uri, 'close socket')
|
||||
try:
|
||||
self.socket.shutdown(socket.SHUT_RDWR)
|
||||
@ -253,8 +260,8 @@ class EventStream:
|
||||
self.udp = {v.socket.fileno(): v for v in udp}
|
||||
|
||||
def wait_ready(self, timeout):
|
||||
ready = select(Stream.select_dict, [], [], timeout)[0]
|
||||
return [Stream.select_dict[f] for f in ready]
|
||||
rd, wr = select(Stream.select_read, Stream.select_write, [], timeout)[0:2]
|
||||
return [Stream.select_read[f] for f in rd] + [Stream.select_write[f] for f in wr]
|
||||
|
||||
def get_events(self, maxevents=20):
|
||||
"""return events from all streams
|
||||
@ -278,7 +285,7 @@ class EventStream:
|
||||
self.streams[uri] = stream = streamcls(uri, **kwargs)
|
||||
print('added stream', uri, kwargs)
|
||||
except Exception as e:
|
||||
print('can not connect to', uri, repr(e))
|
||||
print('can not connect to', uri, repr(e), streamcls)
|
||||
continue
|
||||
device = stream.tags.get('device')
|
||||
events.append(('stream', kwargs.get('instrument', '0'),
|
||||
|
Reference in New Issue
Block a user