Skip to content

compas_acoustics.worker

Run compas_acoustics in a second interpreter, the worker, and call it over HTTP with protobuf payloads.

For a Python 3.9 host, where the binaural and ambisonics methods, STI and G are not available. client starts the worker (service, in the Python >= 3.11 that install creates) on first use, on a free port of 127.0.0.1 with a random token; it stops with the session.

Classes

Client

Client(port, token, process=None, python=None, log=None)

A running worker: client.simulate(...) calls compas_acoustics.worker.api.simulate there.

Methods:

call
call(function, *args, call_id=None, **kwargs)

Call function of the worker API; a call_id lets cancel and progress reach it.

cancel
cancel(call_id)

Ask the call call_id to stop at its next stage; False if the worker has no such call.

progress
progress(call_id)

The call's last stage, {"stage", "done", "of", "cancelled"}; None once it answered.

start classmethod
start(python)

Start a worker with python and wait until it answers; refuse one that runs other sources.

stop
stop()

Ask the worker to shut down, and end its process if it does not.

WorkerError

WorkerError(status, text)

Bases: RuntimeError

An error the worker answered with: status is the HTTP status, the message the worker's text.

Functions:

analyse

analyse(ir)

Analyse ir here, with STI and G from the worker when this Python's pyrato cannot compute them.

STI and G need pyrato >= 1.0, which needs Python >= 3.11. Returns the Analyser, its analysis_data filled, and the messages of the UserWarnings raised in the worker.

client

client()

This session's worker, started on first use; None if no worker interpreter is configured.

fingerprint

fingerprint()

A hash of the package's Python sources: two installations of one development version can differ.

simulate

simulate(scene, method, settings, references=None)

Run method ("binaural", "ambisonics" or "mono") with settings on scene in the worker.

The responses are stored on scene.ir_graph under the method's name, as Scene.simulate stores them; references ({key: ImpulseResponse}) is the method's reference. Returns the responses by key and the messages of the UserWarnings raised in the worker.

stop

stop()

Stop this session's worker, if it has one.

stop_running_workers

stop_running_workers(workers=None)

Ask every worker recorded in WORKERS to shut down, and forget those that are gone.

On Windows a running worker holds the files of the environment that install replaces.

worker_python

worker_python()

$COMPAS_ACOUSTICS_WORKER_PYTHON, else the interpreter in CONFIG; None if neither exists.