RxPY
RxPY copied to clipboard
Debounce operator does not ignore values, it queues them with delay
Describe the bug Debounce operator does not ignore values, it queues them with delay.
To Reproduce
test = rx.interval(0.1).pipe(
ops.debounce(1.5, scheduler=CurrentThreadScheduler()),
).subscribe(print)
Truth be told, I am using a socket as the source. It's providing the data to a Subject
in a thread different from the main one. All rx execution happens in that thread.
Expected behavior I would expect values from 2 to around 15 to be dropped.
Additional context Add any other context about the problem here.
- OS Linux
- RxPY version 4.0.4
- Python version 3.10.5
You cannot use the CurrentThreadScheduler here. It cannot schedule blocking work on a single thread (current) without blocking everything else while waiting, so things will not behave as you expect. You need to use a thread-based scheduler e.g TimeoutScheduler, but perhaps ThreadPoolScheduler is a better choice.
@dbrattli, thank you for the help. Unfortunately, these two schedulers do not get the job done. It seems that I have to change something in my threaded app.
When I use these schedulers, the entire pipeline freezes. Could the issue be that I block the main thread with some work while in parallel in another thread, the Rx stream runs with the debounce operator?
It it's not easy to say. Multi-threaded applications can be complex to get right. You will have to experiment and get into the details of this. But you will have to use another scheduler for debounce than the CurrentThreadScheduler
.