fix: fix RuntimeError: cannot join current thread

fix #161
This commit is contained in:
acgnhik 2023-10-09 15:14:02 +08:00
parent d3579fae90
commit 0dda7e7227

View File

@ -1,11 +1,10 @@
from queue import Queue from queue import Queue
from threading import Thread from threading import Thread, current_thread
from typing import Any, Callable, Optional, TypeVar from typing import Any, Callable, Optional, TypeVar
from reactivex import Observable, abc from reactivex import Observable, abc
from reactivex.disposable import CompositeDisposable, Disposable, SerialDisposable from reactivex.disposable import CompositeDisposable, Disposable, SerialDisposable
_T = TypeVar('_T') _T = TypeVar('_T')
@ -41,7 +40,8 @@ def observe_on_new_thread(
nonlocal disposed nonlocal disposed
disposed = True disposed = True
queue.put(lambda: None) queue.put(lambda: None)
thread.join() if thread is not current_thread():
thread.join()
subscription.disposable = source.subscribe( subscription.disposable = source.subscribe(
on_next, on_error, on_completed, scheduler=scheduler on_next, on_error, on_completed, scheduler=scheduler