tvm_tirx.support.popen_pool.PopenWorker#

class tvm_tirx.support.popen_pool.PopenWorker(initializer=None, initargs=(), maximum_uses=None, stdout=None, stderr=None)#

Bases: object

A subprocess worker via Popen.

PopenWorker provides a low-level API to interact with a separate process via Popen.

Parameters:
  • initializer (callable or None) – A callable initializer, or None

  • initargs (Tuple[object]) – A tuple of args for the initializer

  • maximum_uses (Optional[int]) – The maximum number of times a process can be used before being recycled, i.e. killed and restarted. If None, the process will be reused until an operation times out.

  • stdout (Union[None, int, IO[Any]]) – The standard output streams handler specified for the popen process.

  • stderr (Union[None, int, IO[Any]]) – The standard error streams handler specified for the popen process.

kill()#

Kill the current running process and cleanup.

Note

The worker can start a new process when send is called again.

join(timeout=None)#

Join the current process worker before it terminates.

Parameters:

timeout (Optional[number]) – Timeout value, block at most timeout seconds if it is a positive number.

is_alive()#

Check if the process is alive

send(fn, args=(), kwargs=None, timeout=None)#

Send a new function task fn(*args, **kwargs) to the subprocess.

Parameters:
  • fn (function) – The function to be invoked.

  • args (list) – Positional argument.

  • kwargs (dict) – Keyword arguments

  • timeout (float) – Timeout value when executing the function

Note

The caller must call recv before calling the next send in order to make sure the timeout and child process exit won’t affect the later requests.

recv()#

Receive the result of the last send.

Returns:

result (object) – The result of the last send.

Raises:
  • ChildProcessError – if the child process exited abnormally.:

  • TimeoutError – if timeout happens:

  • Exception – if other exception happens during the execution.: