Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: windowwithtimeorcount thread unsafe #700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions reactivex/operators/_windowwithtimeorcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,49 +39,53 @@ def create_timer(_id: int):
timer_d.disposable = m

def action(scheduler: abc.SchedulerBase, state: Any = None):
nonlocal n, s, window_id
if _id != window_id:
return

n = 0
window_id += 1
new_id = window_id
s.on_completed()
s = Subject()
observer.on_next(add_ref(s, ref_count_disposable))
create_timer(new_id)
with source.lock:
nonlocal n, s, window_id
if _id != window_id:
return

n = 0
window_id += 1
new_id = window_id
s.on_completed()
s = Subject()
observer.on_next(add_ref(s, ref_count_disposable))
create_timer(new_id)

m.disposable = _scheduler.schedule_relative(timespan, action)

observer.on_next(add_ref(s, ref_count_disposable))
create_timer(0)

def on_next(x: _T) -> None:
nonlocal n, s, window_id
new_window = False
new_id = 0

s.on_next(x)
n += 1
if n == count:
new_window = True
n = 0
window_id += 1
new_id = window_id
s.on_completed()
s = Subject()
observer.on_next(add_ref(s, ref_count_disposable))

if new_window:
create_timer(new_id)
with source.lock:
nonlocal n, s, window_id
new_window = False
new_id = 0

s.on_next(x)
n += 1
if n == count:
new_window = True
n = 0
window_id += 1
new_id = window_id
s.on_completed()
s = Subject()
observer.on_next(add_ref(s, ref_count_disposable))

if new_window:
create_timer(new_id)

def on_error(e: Exception) -> None:
s.on_error(e)
observer.on_error(e)
with source.lock:
s.on_error(e)
observer.on_error(e)

def on_completed() -> None:
s.on_completed()
observer.on_completed()
with source.lock:
s.on_completed()
observer.on_completed()

group_disposable.add(
source.subscribe(on_next, on_error, on_completed, scheduler=scheduler_)
Expand Down