Skip to content

singleprocesshandler

messageflux.multiprocessing.singleprocesshandler

ServiceFactory

This class is used to create a service instance.

create_service abstractmethod

create_service(instance_index, total_instances)

creates the service instance. this will run in the child service

Parameters:

Name Type Description Default
instance_index int

the instance index (0 based) out of all the indexes

required
total_instances int

the total number of indexes

required

Returns:

Type Description
BaseService

an instance of BaseService

SingleProcessHandler

SingleProcessHandler(
    service_factory,
    instance_index,
    total_instances,
    live_check_interval=60,
    live_check_timeout=10,
)

This class is used to handle a single process.

instance_index property

instance_index

the index of this service instance

pid property

pid

the pid of the child process (or None if no child process exists)

process property

process

the child process object for this instance (if exists.)

is_alive

is_alive()

returns whether the child process is alive

Returns:

Type Description
bool

True if the child process is alive, False otherwise

kill

kill()

tries to forcefully KILL the child process

start

start(exit_callback)

Start the service.

Parameters:

Name Type Description Default
exit_callback Callable[[SingleProcessHandler], None]

a callback to call when the process has exited

required

Returns:

Type Description
Thread

a thread that runs that instance.

stop

stop()

requests the child process to stop

terminate

terminate()

tries to forcefully terminate the child process