jina.peapods.pea

class jina.peapods.pea.PeaMeta[source]

Bases: type

Meta class of BasePea to enable switching between thread and process backend.

class jina.peapods.pea.BasePea(args)[source]

Bases: object

BasePea is an unary service unit which provides network interface and communicates with others via protobuf and ZeroMQ

Create a new BasePea object

Parameters
  • args (Union[Namespace, Dict]) – the arguments received from the CLI

  • pea_id – the id used to separate the storage of each pea, only used when args.separate_storage=True

name = None

this is the process name

handle(msg)[source]

Register the current message to this pea, so that all message-related properties are up-to-date, including request, prev_requests, message, prev_messages. And then call the executor to handle this message if its envelope’s status is not ERROR, else skip handling of message.

Parameters

msg (Message) – the message received

Return type

BasePea

property is_idle

Return True when current time is max_idle_time seconds late than the last active time

Return type

bool

property request

Get the current request body inside the protobuf message

Return type

Request

property message

Get the current protobuf message to be processed

Return type

Message

property request_type
Return type

str

load_executor()[source]

Load the executor to this BasePea, specified by uses CLI argument.

print_stats()[source]
save_executor(dump_interval=0)[source]

Save the contained executor

Parameters

dump_interval (int) – the time interval for saving

property expect_parts

The expected number of partial messages before trigger handle()

Return type

int

property partial_requests

The collected partial requests under the current request_id

Return type

List[Request]

property partial_messages

The collected partial messages under the current request_id

Return type

List[Message]

pre_hook(msg)[source]

Pre-hook function, what to do after first receiving the message

Return type

BasePea

post_hook(msg)[source]

Post-hook function, what to do before handing out the message

Return type

BasePea

set_ready(*args, **kwargs)[source]

Set the status of the pea to ready

unset_ready(*args, **kwargs)[source]

Set the status of the pea to shutdown

msg_callback(msg)[source]

Callback function after receiving the message

When nothing is returned then the nothing is send out via zmqlet.sock_out.

Return type

Optional[Message]

loop_body()[source]

The body of the request loop

Note

Class inherited from BasePea must override this function. And add set_ready() when your loop body is started

load_plugins()[source]
loop_teardown()[source]

Stop the request loop

run()[source]

Start the request loop of this BasePea. It will listen to the network protobuf message via ZeroMQ.

check_memory_watermark()[source]

Check the memory watermark

post_init()[source]

Post initializer after the start of the request loop via run(), so that they can be kept in the same process/thread as the request loop.

send_terminate_signal()[source]

Gracefully close this pea and release all resources

Return type

None

property status

Send the control signal STATUS to itself and return the status

start()[source]
Return type

BasePea

close()[source]
Return type

None