FAQ

Can I use private methods and attributes?

By default, private methods and attributes (name starting with a _) are not exposed to the remote side.

However, you can force private methods to be exposed by decorating them with @heros.inspect.force_remote.

For attributes there is currently no straight forward way to force this.

I am observing timeouts in the HERO communication. What can I do?

If a timeout occurs, HEROS will print an error like

2025-10-23 17:41:47,609 heros [heros.py:70 _query_selector]: Stream interrupted when querying peer EntityGlobalId { zid: 2554c3255fd4ff7dce726aba72afd04f, eid: 0 } with arguments ('@object/heros/*/_discover',) and {'target': QueryTarget.ALL, 'timeout': 2.0}: b'Timeout'. If this error persists, consult the HEROS documentation on 'debuging'.

to the terminal. This can occur if a peer is in an unresponsive state and takes to long to respond.

All HERO scripts/processes can be started with RUST_LOG=DEBUG, which enables zenoh logging. For example

RUST_LOG=DEBUG uv run hero-monitor

If this does not help, another way is to setup a zenoh router. Therefore download the newest “standalone” package for your system here and unpack it.

Note

It does not matter on which machine you are doing this as long as it is connected to the same network as the offending peer.

Move into the unpacked folder and run

RUST_LOG=DEBUG ./zenohd

in a terminal. Now the router should connect to all peers it finds on the network. For each peer it prints a line like

Important

You need to run zenohd with the correct multicast group config.

2025-10-23T15:47:22.218912Z DEBUG acc-0 ThreadId(04) zenoh_transport::unicast::establishment::accept: New transport link accepted from 2554c3255fd4ff7dce726aba72afd04f to 2890d320dce65ff47c7ea57b87954cc6: TransportLinkUnicast { link: Link { src: tcp/[::ffff:192.168.1.130]:7447, dst: tcp/[::ffff:192.168.1.130]:54838, mtu: 49152, is_reliable: true, is_streamed: true }, config: TransportLinkUnicastConfig { direction: Inbound, batch: BatchConfig { mtu: 49152, is_streamed: true, is_compression: false }, priorities: None, reliability: None } }

Now search for the connecting zid you obtained from the timeout error message, in this example 2554c3255fd4ff7dce726aba72afd04f. The router knows which IP address this peer runs on, here tcp/[::ffff:192.168.1.130]:7447.

Sometimes it is enough to restart the blocking HERO, but in general it is a sign of a intermittent connection.

Important

We observed that if the network topology changed in combination with a stuck zenoh peer, the above method will fail because it seems that all peers get blocked by some kind of timeout cascade. The only way to fix this currently is shutting off all zenoh peers (HEROs, HERO-monitors,…) and starting them again. See also this issue <> for further tips and updates.

Note

If the endpoint timing out is not _discover but for example _@object/heros/my_hero/slow_calc, this indicates that your function slow_calc takes to long to execute. If you require this, raise the zenoh query timeout as a temporary solution and write a feature request.

My script does not terminate. What is going on?

The zenoh python bindings serve every queryable, subscriber and liveliness token of a HERO from its own thread. Python joins those threads before it ends the process, and they only end once the HERO has released its zenoh declarations. HEROS does that for you during interpreter shutdown, so a plain script terminates even if it never destroys its HEROs explicitly.

Shutdown still has to close the zenoh session. If that close fails, HEROS logs

Closing the zenoh session timed out, which can leave stale peers behind.

Seeing this means the close is stuck rather than slow, see the next entry.

If you want to control when the teardown happens rather than leave it to interpreter shutdown, use the HERO as a context manager:

with MyHero("my_hero") as hero:
    ...

Closing the zenoh session times out. Why?

Session::close waits for the link open attempts that are still in flight, and each of those runs until transport/unicast/open_timeout expires. zenoh gives up on the close after 10 s of its own, so with zenoh’s default of 10000 ms a single open attempt in flight is enough to make every close fail. HEROS therefore lowers open_timeout to 1000 ms, see HEROS_ZENOH_CONFIG.

That shortens the wait but does not remove its cause. Open attempts keep being made when two machines can reach each other over more than one network, for example a VPN and the LAN underneath it. zenoh keeps one link per peer (transport/unicast/max_links), so the second path can never turn into a link, and both sides keep retrying it. The more peer pairs that are reachable twice, the more time every close spends waiting.

Check how many links the session holds and how many peers appear twice:

import time, zenoh
from heros.zenoh import build_config

session = zenoh.open(build_config("heros"))
time.sleep(3)
for link in session.info.links():
    print(link.zid, link.dst)

src tells you which of your own interfaces a link uses. A peer that appears twice, once per interface, is a peer pair that is reachable over two networks. Give each machine one path into the realm to get rid of them, by listening only on the address the realm should use:

HEROS_ZENOH_CONFIG='{"listen":{"endpoints":["tcp/<the-one-address>:0"]},"scouting":{"multicast":{"enabled":false}}}'
HEROS_ZENOH_CONNECT=tcp/<router>:7447

This keeps the realm peer to peer. A zenoh router bootstraps discovery where multicast does not reach, for example across a VPN, but gossip then gives every HERO direct links to every other one, and those links survive the router going away.

Can I use Heros with ARTIQ without using Atomiq?

Yes, even if we do not recommend it an there is no real point in it other than for a temporary transitionary setup! Just install HEROS within your flake.nix (adapt the version to the latest):

heros = pkgs.python3Packages.buildPythonPackage rec {
  name = "heros";
  pname = "heros";
  format = "pyproject";
  version = "0.5.0";
  nativeBuildInputs = [
    pkgs.autoPatchelfHook
    ];
  src = pkgs.python3Packages.fetchPypi {
    inherit pname version;
    sha256 = "lXvd8N1BnHRWidwESy42ZlRopEX/y/uLXv+NCnxPWwo=";
  };
  buildInputs = [ pkgs.python3Packages.cbor2 pkgs.python3Packages.hatchling pkgs.python3Packages.numpy pkgs.python3Packages.zenoh];
};

and add heros to the python packages loaded on shell creation.

Note

If you are using Atomiq, this is all handled automatically and you can just add your HERO to the components DB with the $ identifier.

To use a remote hero as a device in the device DB, you have to circumvent the device manager to be passed to the RemoteHERO class by creating a device like:

class ArtiqRemoteHERO(RemoteHERO)
  def __new__(cls, dmgr, name: str, realm: str = "heros", *args, **kwargs):
      return RemoteHERO.__new__(cls, name,realm, *args, **kwargs)

  def __init__(self, dmgr,  name: str, realm: str="heros", *args, **kwargs):
      super().__init__(name, realm, *args, **kwargs)

and adding it to the device db:

device_db["my_hero"] = {
   "type": "local",
   "module": "my.lib",
   "class":"ArtiqRemoteHERO",
   "arguments": {
       "name":"my_remote_hero"
       }
}