ReactiveX / RxPY

ReactiveX for Python
https://rxpy.rtfd.io
MIT License
4.81k stars 361 forks source link

Observable.interval raises "AttributeError: 'int' object has no attribute 'dispose'" with the AsyncIOScheduler #91

Closed frederikaalund closed 8 years ago

frederikaalund commented 8 years ago

The following program illustrates the problem:

import asyncio
import rx
import time

scheduler = rx.concurrency.AsyncIOScheduler()
sub0 = rx.Observable.interval(1000, scheduler=scheduler) \
    .subscribe(print, print, print)

try:
    loop = asyncio.get_event_loop()
    loop.run_forever()
except:
    pass

sub0.dispose()

I would expect the above to exit normally. However, I get the following error message instead:

Traceback (most recent call last):
  File "./rx_test.py", line 17, in <module>
    sub0.dispose()
  File "/opt/sd/lib/python3.5/site-packages/rx/autodetachobserver.py", line 40, in dispose
    self.m.dispose()
  File "/opt/sd/lib/python3.5/site-packages/rx/disposables/booleandisposable.py", line 50, in dispose
    old.dispose()
  File "/opt/sd/lib/python3.5/site-packages/rx/disposables/compositedisposable.py", line 63, in dispose
    disposable.dispose()
  File "/opt/sd/lib/python3.5/site-packages/rx/disposables/booleandisposable.py", line 50, in dispose
    old.dispose()
AttributeError: 'int' object has no attribute 'dispose'

Python 3.5.1 and RxPY master branch (where I have applied the fix for issue #90).

frederikaalund commented 8 years ago

Just tested the develop branch. The issue is there too.

frederikaalund commented 8 years ago

I noticed that the Observable.interval normally outputs 0, 1, 2, 3, ... but with the AsyncIOScheduler, it outputs 0, 0, 0, 0, ...

dbrattli commented 8 years ago

I think I've found the bug. Creating a fix soon ...

frederikaalund commented 8 years ago

Ah, excellent. I had a pull request on the way (see this commit) but I much prefer a fix from the original author. Cheers!

Edit: I think this bug might also apply to some of the other mainloopschedulers.

dbrattli commented 8 years ago

Yes, you are right, and thanks a lot for reporting these issues. It also uncovered a different problem. We also have to check that scheduled actions returns disposables before using the return value as a disposable. Usually an action returns None, so it's not a problem. I'll make some more fixes later.

frederikaalund commented 8 years ago

You're welcome. Cheers for the timely replies and fixes! I will test the latter tomorrow.

frederikaalund commented 8 years ago

Just tested b2836e7 and it completely solves the issue. Cheers!

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.