qat.generators.AbstractGenerator

class qat.generators.AbstractGenerator(*args, **kwargs)

Abstract interface for a batch generator.

An abctract generator has a single abstract method ‘generate’. This generate function can return either:

  • a generator (use of keyword ‘yield’)

  • a Batch

An optional method ‘post_process’ can be also defined to parse the result. This method is used if one of the following condition is met:

The batch generator section give some examples of dummy batch generators

abstract generate(specs, *args, **kwargs)

Generates a batch. This function could return either an iterator or a Batch

serve(port, host_ip='localhost', server_type=None, ssl_cert: Optional[str] = None, ssl_key: Optional[str] = None, ssl_ca: Optional[str] = None)

Runs the batch generator inside a server

Parameters
  • port (int) – the port on which to listen

  • host_ip (str, optional) – the hostname on which to publish the API. Defaults to ‘localhost’

  • server_type (str, optional) –

    type of server. The different types or server are:

    • ”simple”: single-thread server, accepts one connection at a time (default server type)

    • ”threaded”: multi-thread server, each connection starts a new thread

    • ”pool”: multi-thread server, each connection runs in a thread, with a maximum of 10 running threads

    • ”fork”: multi-process server, each connection runs in a new process

  • ssl_cert (str, optional) – path to the server SSL certificate (mandatory for SSL) Default: None

  • ssl_key (str, optional) – path to the server SSL key (mandatory for SSL) Default: None

  • ssl_ca (str, optional) – path to the server SSL certificate authority (only serves requests with signed certificates) Default: None

wrapper_post_process(result)

Post process the result returned by the second part of the stack.

First, this method will call the post process method of the plugin piped to this AbstractGenerator

Then, if post processing the result is a BatchResult, the result is post processed by this AbstractGenetor:

  • If ‘generate’ returned a generator, the result is sent to this generator

  • If ‘generate’ returned a Batch, call method ‘post_process’

Parameters

result (BatchResult) – batch result

Returns

parsed post processed result

Return type

ParsedPostProcessedResult