Schedulers

class reactivex.scheduler.CatchScheduler(scheduler, handler)
__init__(scheduler, handler)

Wraps a scheduler, passed as constructor argument, adding exception handling for scheduled actions. The handler should return True to indicate it handled the exception successfully. Falsy return values will be taken to indicate that the exception should be escalated (raised by this scheduler).

Parameters
  • scheduler (SchedulerBase) – The scheduler to be wrapped.

  • handler (Callable[[Exception], bool]) – Callable to handle exceptions raised by wrapped scheduler.

property now: datetime

Represents a notion of time for this scheduler. Tasks being scheduled on a scheduler will adhere to the time denoted by this property.

Return type

datetime

Returns

The scheduler’s current time, as a datetime instance.

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_periodic(period, action, state=None)

Schedules a periodic piece of work.

Parameters
  • period (Union[timedelta, float]) – Period in seconds or timedelta for running the work periodically.

  • action (Callable[[Optional[TypeVar(_TState)]], Optional[TypeVar(_TState)]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] Initial state passed to the action upon the first iteration.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled recurring action (best effort).

class reactivex.scheduler.CurrentThreadScheduler

Represents an object that schedules units of work on the current thread. You should never schedule timeouts using the CurrentThreadScheduler, as that will block the thread while waiting.

Each instance manages a number of trampolines (and queues), one for each thread that calls a schedule method. These trampolines are automatically garbage-collected when threads disappear, because they’re stored in a weak key dictionary.

classmethod singleton()

Obtain a singleton instance for the current thread. Please note, if you pass this instance to another thread, it will effectively behave as if it were created by that other thread (separate trampoline and queue).

Return type

CurrentThreadScheduler

Returns

The singleton CurrentThreadScheduler instance.

__init__()
class reactivex.scheduler.EventLoopScheduler(thread_factory=None, exit_if_empty=False)

Creates an object that schedules units of work on a designated thread.

__init__(thread_factory=None, exit_if_empty=False)
schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_periodic(period, action, state=None)

Schedules a periodic piece of work.

Parameters
  • period (Union[timedelta, float]) – Period in seconds or timedelta for running the work periodically.

  • action (Callable[[Optional[TypeVar(_TState)]], Optional[TypeVar(_TState)]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] Initial state passed to the action upon the first iteration.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled recurring action (best effort).

run()

Event loop scheduled on the designated event loop thread. The loop is suspended/resumed using the condition which gets notified by calls to Schedule or calls to dispose.

Return type

None

dispose()

Ends the thread associated with this scheduler. All remaining work in the scheduler queue is abandoned.

Return type

None

class reactivex.scheduler.HistoricalScheduler(initial_clock=None)

Provides a virtual time scheduler that uses datetime for absolute time and timedelta for relative time.

__init__(initial_clock=None)

Creates a new historical scheduler with the specified initial clock value.

Parameters

initial_clock (Optional[datetime]) – Initial value for the clock.

class reactivex.scheduler.ImmediateScheduler

Represents an object that schedules units of work to run immediately, on the current thread. You’re not allowed to schedule timeouts using the ImmediateScheduler since that will block the current thread while waiting. Attempts to do so will raise a WouldBlockException.

static __new__(cls)
Return type

ImmediateScheduler

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

class reactivex.scheduler.NewThreadScheduler(thread_factory=None)

Creates an object that schedules each unit of work on a separate thread.

__init__(thread_factory=None)
schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_periodic(period, action, state=None)

Schedules a periodic piece of work.

Parameters
  • period (Union[timedelta, float]) – Period in seconds or timedelta for running the work periodically.

  • action (Callable[[Optional[TypeVar(_TState)]], Optional[TypeVar(_TState)]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] Initial state passed to the action upon the first iteration.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled recurring action (best effort).

class reactivex.scheduler.ThreadPoolScheduler(max_workers=None)

A scheduler that schedules work via the thread pool.

class ThreadPoolThread(executor, target)

Wraps a concurrent future as a thread.

__init__(executor, target)
__init__(max_workers=None)
class reactivex.scheduler.TimeoutScheduler

A scheduler that schedules work via a timed callback.

static __new__(cls)
Return type

TimeoutScheduler

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

class reactivex.scheduler.TrampolineScheduler

Represents an object that schedules units of work on the trampoline. You should never schedule timeouts using the TrampolineScheduler, as it will block the thread while waiting.

Each instance has its own trampoline (and queue), and you can schedule work on it from different threads. Beware though, that the first thread to call a schedule method while the trampoline is idle will then remain occupied until the queue is empty.

__init__()
schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_required()

Test if scheduling is required.

Gets a value indicating whether the caller must call a schedule method. If the trampoline is active, then it returns False; otherwise, if the trampoline is not active, then it returns True.

Return type

bool

ensure_trampoline(action)

Method for testing the TrampolineScheduler.

Return type

Optional[DisposableBase]

class reactivex.scheduler.VirtualTimeScheduler(initial_clock=0)

Virtual Scheduler. This scheduler should work with either datetime/timespan or ticks as int/int

__init__(initial_clock=0)

Creates a new virtual time scheduler with the specified initial clock value.

Parameters

initial_clock (Union[datetime, float]) – Initial value for the clock.

property now: datetime

Represents a notion of time for this scheduler. Tasks being scheduled on a scheduler will adhere to the time denoted by this property.

Return type

datetime

Returns

The scheduler’s current time, as a datetime instance.

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

start()

Starts the virtual time scheduler.

Return type

Any

stop()

Stops the virtual time scheduler.

Return type

None

advance_to(time)

Advances the schedulers clock to the specified absolute time, running all work til that point.

Parameters

time (Union[datetime, float]) – Absolute time to advance the schedulers clock to.

Return type

None

advance_by(time)

Advances the schedulers clock by the specified relative time, running all work scheduled for that timespan.

Parameters

time (Union[timedelta, float]) – Relative time to advance the schedulers clock by.

Return type

None

sleep(time)

Advances the schedulers clock by the specified relative time.

Parameters

time (Union[timedelta, float]) – Relative time to advance the schedulers clock by.

Return type

None

classmethod add(absolute, relative)

Adds a relative time value to an absolute time value.

Parameters
  • absolute (Union[datetime, float]) – Absolute virtual time value.

  • relative (Union[timedelta, float]) – Relative virtual time value to add.

Return type

Union[datetime, float]

Returns

The resulting absolute virtual time sum value.

class reactivex.scheduler.eventloop.AsyncIOScheduler(loop)

A scheduler that schedules work via the asyncio mainloop. This class does not use the asyncio threadsafe methods, if you need those please use the AsyncIOThreadSafeScheduler class.

__init__(loop)

Create a new AsyncIOScheduler.

Parameters

loop (AbstractEventLoop) – Instance of asyncio event loop to use; typically, you would get this by asyncio.get_event_loop()

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

property now: datetime

Represents a notion of time for this scheduler. Tasks being scheduled on a scheduler will adhere to the time denoted by this property.

Return type

datetime

Returns

The scheduler’s current time, as a datetime instance.

class reactivex.scheduler.eventloop.AsyncIOThreadSafeScheduler(loop)

A scheduler that schedules work via the asyncio mainloop. This is a subclass of AsyncIOScheduler which uses the threadsafe asyncio methods.

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

class reactivex.scheduler.eventloop.EventletScheduler(eventlet)

A scheduler that schedules work via the eventlet event loop.

http://eventlet.net/

__init__(eventlet)

Create a new EventletScheduler.

Parameters

eventlet (Any) – The eventlet module to use; typically, you would get this by import eventlet

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

property now: datetime

Represents a notion of time for this scheduler. Tasks being scheduled on a scheduler will adhere to the time denoted by this property.

Return type

datetime

Returns

The scheduler’s current time, as a datetime instance.

class reactivex.scheduler.eventloop.GEventScheduler(gevent)

A scheduler that schedules work via the GEvent event loop.

http://www.gevent.org/

__init__(gevent)

Create a new GEventScheduler.

Parameters

gevent (Any) – The gevent module to use; typically ,you would get this by import gevent

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

property now: datetime

Represents a notion of time for this scheduler. Tasks being scheduled on a scheduler will adhere to the time denoted by this property.

Return type

datetime

Returns

The scheduler’s current time, as a datetime instance.

class reactivex.scheduler.eventloop.IOLoopScheduler(loop)

A scheduler that schedules work via the Tornado I/O main event loop.

Note, as of Tornado 6, this is just a wrapper around the asyncio loop.

http://tornado.readthedocs.org/en/latest/ioloop.html

__init__(loop)

Create a new IOLoopScheduler.

Parameters

loop (Any) – The ioloop to use; typically, you would get this by tornado import ioloop; ioloop.IOLoop.current()

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

property now: datetime

Represents a notion of time for this scheduler. Tasks being scheduled on a scheduler will adhere to the time denoted by this property.

Return type

datetime

Returns

The scheduler’s current time, as a datetime instance.

class reactivex.scheduler.eventloop.TwistedScheduler(reactor)

A scheduler that schedules work via the Twisted reactor mainloop.

__init__(reactor)

Create a new TwistedScheduler.

Parameters

reactor (Any) – The reactor to use; typically, you would get this by from twisted.internet import reactor

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

property now: datetime

Represents a notion of time for this scheduler. Tasks being scheduled on a scheduler will adhere to the time denoted by this property.

Return type

datetime

Returns

The scheduler’s current time, as a datetime instance.

class reactivex.scheduler.mainloop.GtkScheduler(glib)

A scheduler that schedules work via the GLib main loop used in GTK+ applications.

See https://wiki.gnome.org/Projects/PyGObject

__init__(glib)

Create a new GtkScheduler.

Parameters

glib (Any) – The GLib module to use; typically, you would get this by >>> import gi >>> gi.require_version(‘Gtk’, ‘3.0’) >>> from gi.repository import GLib

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_periodic(period, action, state=None)

Schedules a periodic piece of work to be executed in the loop.

Parameters
  • period (Union[timedelta, float]) – Period in seconds for running the work repeatedly.

  • action (Callable[[Optional[TypeVar(_TState)]], Optional[TypeVar(_TState)]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) –

    [Optional] state to be given to the action function.

    Returns:

    The disposable object used to cancel the scheduled action (best effort).

Return type

DisposableBase

class reactivex.scheduler.mainloop.PyGameScheduler(pygame)

A scheduler that schedules works for PyGame.

Note that this class expects the caller to invoke run() repeatedly.

http://www.pygame.org/docs/ref/time.html http://www.pygame.org/docs/ref/event.html

__init__(pygame)

Create a new PyGameScheduler.

Parameters

pygame (Any) – The PyGame module to use; typically, you would get this by import pygame

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime. :type duetime: Union[timedelta, float] :param duetime: Relative time after which to execute the action. :type action: Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]] :param action: Action to be executed. :type state: Optional[TypeVar(_TState)] :param state: [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

class reactivex.scheduler.mainloop.QtScheduler(qtcore)

A scheduler for a PyQt5/PySide2 event loop.

__init__(qtcore)

Create a new QtScheduler.

Parameters

qtcore (Any) – The QtCore instance to use; typically you would get this by either import PyQt5.QtCore or import PySide2.QtCore

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_periodic(period, action, state=None)

Schedules a periodic piece of work to be executed in the loop.

Parameters
  • period (Union[timedelta, float]) – Period in seconds for running the work repeatedly.

  • action (Callable[[Optional[TypeVar(_TState)]], Optional[TypeVar(_TState)]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) –

    [Optional] state to be given to the action function.

    Returns:

    The disposable object used to cancel the scheduled action (best effort).

Return type

DisposableBase

class reactivex.scheduler.mainloop.TkinterScheduler(root)

A scheduler that schedules work via the Tkinter main event loop.

http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html http://effbot.org/tkinterbook/widget.htm

__init__(root)

Create a new TkinterScheduler.

Parameters

root (Any) – The Tk instance to use; typically, you would get this by import tkinter; tkinter.Tk()

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

class reactivex.scheduler.mainloop.WxScheduler(wx)

A scheduler for a wxPython event loop.

__init__(wx)

Create a new WxScheduler.

Parameters

wx (Any) – The wx module to use; typically, you would get this by import wx

cancel_all()

Cancel all scheduled actions.

Should be called when destroying wx controls to prevent accessing dead wx objects in actions that might be pending.

Return type

None

schedule(action, state=None)

Schedules an action to be executed.

Parameters
  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_relative(duetime, action, state=None)

Schedules an action to be executed after duetime.

Parameters
  • duetime (Union[timedelta, float]) – Relative time after which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_absolute(duetime, action, state=None)

Schedules an action to be executed at duetime.

Parameters
  • duetime (Union[datetime, float]) – Absolute time at which to execute the action.

  • action (Callable[[SchedulerBase, Optional[TypeVar(_TState)]], Optional[DisposableBase]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) – [Optional] state to be given to the action function.

Return type

DisposableBase

Returns

The disposable object used to cancel the scheduled action (best effort).

schedule_periodic(period, action, state=None)

Schedules a periodic piece of work to be executed in the loop.

Parameters
  • period (Union[timedelta, float]) – Period in seconds for running the work repeatedly.

  • action (Callable[[Optional[TypeVar(_TState)]], Optional[TypeVar(_TState)]]) – Action to be executed.

  • state (Optional[TypeVar(_TState)]) –

    [Optional] state to be given to the action function.

    Returns:

    The disposable object used to cancel the scheduled action (best effort).

Return type

DisposableBase