A Jina Runtime is a procedure that blocks the main process once running (i.e.
run_forever()), therefore must be put into a separated thread/process. Any program/library/package/module that blocks the main process, can be formulated into a
BaseRuntimeclass and then be used in
In the sequel, we call the main process/thread as
M, the process/thread blocked
In Jina, a
BasePeaobject is used to manage a
Runtimeobject’s lifecycle. A
BasePeais a subclass of
threading.Thread, it starts from
Mand once the
Sis spawned, it calls
Runtimemethods in the following order:
Rule of thumb on exception handling: if you are not sure if you should handle exception inside
teardown(), then DO NOT catch exception in them. Exception is MUCH better handled by
BasePeafor managing a
Running the blocking procedure inside
S. Note, once this method is called,
If this method raises any exception,
teardown()will be called.
cancel()for cancelling the forever loop.
threading.Eventor multiprocessing.Event, while
run_forever()polls for this event
Use ZMQ to send a message, while
run_forever()polls for this message
Use HTTP/REST to send a request, while
run_forever()listens to this request
run_forever()for blocking the process/thread.
Method called to prepare the runtime inside
S. Optional in subclasses. The default implementation does nothing.
setup()is called inside