[Python] How to call setup() method from non-main thread in py_trees library?

Discussão em 'Python' iniciado por Stack, Agosto 23, 2025.

  1. Stack

    Stack Membro Participativo

    I'm calling setup() method from py_trees.trees.BehaviourTree() from POST request (this transfers me to a non-main thread) and I'm getting following error:

    ValueError: signal only works in main thread


    How to deal with this without transferring setup() method in the main thread?

    Full trace is provided here:

    File "/usr/src/***/***/***/behavior_trees/tree.py", line 40, in test_tree
    behaviour_tree.setup(timeout=15.0)
    │ └ <function BehaviourTree.setup at 0x7f59a7feb3a0>
    └ <py_trees.trees.BehaviourTree object at 0x7f59a4068d60>

    File "/usr/local/lib/python3.8/site-packages/py_trees/trees.py", line 324, in setup
    setup(
    └ <function setup at 0x7f59a7fe3280>
    File "/usr/local/lib/python3.8/site-packages/py_trees/trees.py", line 109, in setup
    signal.signal(
    │ └ <function signal at 0x7f59b537e3a0>
    └ <module 'signal' from '/usr/local/lib/python3.8/signal.py'>
    File "/usr/local/lib/python3.8/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
    │ │ │ │ │ └ functools.partial(<function setup.<locals>.signal_handler at 0x7f59a40d9ca0>, original_signal_handler=<Handlers.SIG_DFL: 0>)
    │ │ │ │ └ <function _enum_to_int at 0x7f59b537e310>
    │ │ │ └ <Signals.SIGUSR1: 10>
    │ │ └ <function _enum_to_int at 0x7f59b537e310>
    │ └ <built-in function signal>
    └ <module '_signal' (built-in)>

    ValueError: signal only works in main thread

    Continue reading...

Compartilhe esta Página