我正在尝试为Subject
中的每个Observables
创建一个cam
和2个cams
。我通过将对象保存在Cam
类中并在Cam
中为每个cam
存储一个cam_holder
类实例来防止对象被删除。这里的问题是:我最终得到3个rx中继器,它们全部用于cam
中的最后一个cams
,而不是每个中继器。有人可以找到问题所在吗?
cam_holder = {}
class Cam():
cam = None
watchdog = None
buffer_signal = None
stream = None
repeater = None
for cam in cams:
unique_id = str(cam.ip) + ':' + str(cam.onvif)
cam_holder[unique_id] = Cam()
c = cam_holder[unique_id]
c.cam = cam
c.cam.log('starting watchdog')
c.watchdog = rx.subject.Subject()
c.buffer_signal = rx.create(lambda observable, _: c.watchdog.subscribe(observable)).pipe(
ops.filter(lambda x: x==Camera.COMPLETE_BUFFER)
)
c.stream = rx.create(lambda observable, _: c.watchdog.subscribe(observable)).pipe(
ops.buffer_when(lambda: c.buffer_signal)
)
c.stream.subscribe(
on_next = lambda i: process_camera_condition(c.cam,i),
on_error = lambda e: c.cam.log(e),
on_completed = lambda: None,
)
c.buffer_signal.subscribe(
on_next = lambda i: None,
on_error = lambda e: c.cam.log(e),
on_completed = lambda: None,
)
c.repeater = rx.interval(QUERY_INTERVAL).pipe(
ops.do_action(lambda x: c.cam.watchdog(c.watchdog,None))
)
c.repeater.subscribe(
on_next = lambda i: None,
on_error = lambda e: c.cam.log(e),
on_completed = lambda: None,
)