Service

class binp.service.Handler(info, events, handler, task=None)[source]
class binp.service.Info(**data)[source]

Service information

autostart: bool

is service marked to be started automatically

description: str

service description

name: str

service name

restart: bool

is service has to be restarted automatically

restart_delay: float

interval between restarts

status: binp.service.Status

actual service status

class binp.service.Service[source]

Annotate async function as service (background task). Supports automatic (default) and manual start, restarts, restarts delays.

Useful to interact with environment in unpredictable schedule (ex: listen for low-level network requests).

from binp import BINP
from asyncio import sleep

binp = BINP()

@binp.service
async def check_messages():
    while True:
         await sleep(3)
         print("checks")

For scheduling by time better use aiocron instead:

pip install aiocron
from binp import BINP
from aiocron import crontab

binp = BINP()

@crontab("*/5 * * * *")
@binp.journal
async def poll_something():
    print("do something every 5 minutes....")
Conflicts

Services are indexed by name. If multiple services defined with the same name - the old one will be stopped and

the latest one will be used.

Events

  • service_changed - when service status changed. Emits Info

property services

List of all services

Return type

List[Info]

start(name)[source]

Starts single service by name. Does nothing if no such service or service not yet stopped.

stop(name)[source]

Stops service by name. Does nothing if no such service or service stopped.

class binp.service.Status(value)[source]

Service life status

restarting = 'restarting'

service stopped, is waiting before restart

running = 'running'

service up and running

starting = 'starting'

service scheduled to start

stopped = 'stopped'

service stopped and will not be restarted