def observable_window_with_closing_selector(self, window_closing_selector):
    source = self

    def subscribe(observer):
        m = SerialDisposable()
        d = CompositeDisposable(m)
        r = RefCountDisposable(d)
        window = [Subject()]

        observer.on_next(add_ref(window[0], r))

        def on_next(x):
            window[0].on_next(x)

        def on_error(ex):
            window[0].on_error(ex)
            observer.on_error(ex)

        def on_completed():
            window[0].on_completed()
            observer.on_completed()

        d.add(source.subscribe(on_next, on_error, on_completed))

        def create_window_close():
            try:
                window_close = window_closing_selector()
            except Exception as exception:
                log.error(exception % "*** Exception: %s")
                observer.on_error(exception)
                return

            def on_completed():
                window[0].on_completed()
                window[0] = Subject()
                observer.on_next(add_ref(window[0], r))
                create_window_close()

            m1 = SingleAssignmentDisposable()
            m.disposable = m1
            m1.disposable = window_close.take(1).subscribe(noop, on_error, on_completed)

        create_window_close()
        return r
    return AnonymousObservable(subscribe)
dataset/ETHPy150Open ReactiveX/RxPY/rx/linq/observable/window.py/observable_window_with_closing_selector/swapped operands of `%`