Service component

class gevent_tools.service.Service[source]

Service base class for creating standalone or composable services

A service is a container for two things: other services and greenlets. It then provides a common interface for starting and stopping them, based on a subset of the gevent.baseserver interface. This way you can include StreamServer or WSGIServer as child services.

Service also lets you catch exceptions in the greenlets started from this service and introduces the concept of ready, letting us block start() until the service is actually ready.

started

This property returns whether this service has been started

ready[source]

This property returns whether this service is ready for business

_ready()[source]

Internal convenience function to proclaim readiness

add_service(service)[source]

Add a child service to this service

The service added will be started when this service starts, before its _start() method is called. It will also be stopped when this service stops, before its _stop() method is called.

remove_service(service)[source]

Remove a child service from this service

_start()[source]

Empty implementation of service start. Implement me!

Return service.READY or starting will block until _ready() is called (or ready_timeout is reached).

_stop()[source]

Empty implementation of service start. Implement me!

start(block_until_ready=True)[source]

Public interface for starting this service and children. By default it blocks until ready.

stop(timeout=None)[source]

Stop this service and child services

If the server uses a pool to spawn the requests, then stop() also waits for all the handlers to exit. If there are still handlers executing after timeout has expired (default 1 second), then the currently running handlers in the pool are killed.

serve_forever(stop_timeout=None)[source]

Start the service if it hasn’t been already started and wait until it’s stopped.

spawn(func, *args, **kwargs)[source]

Spawn a greenlet under this service

spawn_later(seconds, func, *args, **kwargs)[source]

Spawn a greenlet in the future under this service

catch(type, handler)[source]

Set an error handler for exceptions of type raised in greenlets

This Page