Scheduler#

Schedulers provide means to schedule callbacks asynchronously.

These are used by the subscriber to call the user-provided callback to process each message.

class google.cloud.pubsub_v1.subscriber.scheduler.Scheduler[source]#

Abstract base class for schedulers.

Schedulers are used to schedule callbacks asynchronously.

abstract property queue#

A concurrency-safe queue specific to the underlying concurrency implementation.

This queue is used to send messages back to the scheduling actor.

Type

Queue

abstract schedule(callback, *args, **kwargs)[source]#

Schedule the callback to be called asynchronously.

Parameters
  • callback (Callable) – The function to call.

  • args – Positional arguments passed to the function.

  • kwargs – Key-word arguments passed to the function.

Returns

None

abstract shutdown()[source]#

Shuts down the scheduler and immediately end all pending callbacks.

class google.cloud.pubsub_v1.subscriber.scheduler.ThreadScheduler(executor=None)[source]#

A thread pool-based scheduler.

This scheduler is useful in typical I/O-bound message processing.

Parameters

executor (concurrent.futures.ThreadPoolExecutor) – An optional executor to use. If not specified, a default one will be created.

property queue#

A thread-safe queue used for communication between callbacks and the scheduling thread.

Type

Queue

schedule(callback, *args, **kwargs)[source]#

Schedule the callback to be called asynchronously in a thread pool.

Parameters
  • callback (Callable) – The function to call.

  • args – Positional arguments passed to the function.

  • kwargs – Key-word arguments passed to the function.

Returns

None

shutdown()[source]#

Shuts down the scheduler and immediately end all pending callbacks.