- class jina.serve.runtimes.base.BaseRuntime(args, **kwargs)¶
A Jina Runtime is a procedure that blocks the main process once running (i.e.
run_forever()), therefore should be put into a separated thread/process, or inside the main process of a docker container.
Any program/library/package/module that blocks the main process, can be formulated into a
BaseRuntimeclass and then be started from a
In the sequel, we call the main process/thread as
M, the process/thread blocked
In Jina, a
Podobject is used to manage a
Runtimeobject’s lifecycle. A
Podacts as a
threading.Thread, it starts from
Mand once the
Sis spawned, it uses
Runtimeas a context manager:
run_forever(). Note that this will block
S, step 3 won’t be reached until it is unblocked by
3. When an error occurs during run_forever or cancel signal is reached by the runtime. The run_forever method is cancelled and the managed context is closed. The __exit__ of Runtime guarantees that the Runtime is properly shut by calling teardown.
teardown()pair together, which defines instructions that will be executed before and after. In subclasses, teardown is optional.
In order to cancel the run_forever method of a Runtime, you can use their static cancel method that will make sure that the runtime is properly cancelled.
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
Podfor 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.