can smach co-exist with a pre-existing mainloop?
I'm evaluating smach for use in a ROS node I'm developing. The purpose of this node is to draw graphics using the Panda3D library. This display server will have different states (e.g. blit 2D images sent as ROS messages to the screen, draw 3D graphics using realtime tracking data sent as ROS messages). So, at a high level, it seems natural to use smach to manage such a state machine. However, the strongly recommended way of using Panda3D (like all GUI frameworks I know) is to setup event-driven callbacks and then call Panda's app.run() method, which never returns (until the app is done). I didn't find any documentation or examples referring to use of smach within such an external event loop.
My question is: is it possible to use smach in this kind of environment? If so, how? What are the issues to consider?
All the smach examples I've seen leave the Python script in charge of control flow and the StateMachine.execute() method itself seems to take the role of a main loop. If I relegate overall control to Panda's mainloop, I guess that the smach state would have to be maintained in callbacks that get registered with the Panda event handler. There are various callbacks that could be used in Panda, including an "on every frame" callback.
Briefly looking into the code for StateMachine.execute(), it seems that smach itself assumes the role of the main event loop. So, I guess my best option to make smach co-exist with another main loop is to put the constituent pieces of execute() into custom functions. Then StateMachine._update_once() could be called as frequently as possible from the Panda event loop. I guess something like this approach may be my only option if I want to keep Panda's main loop. I also guess that this approach isn't exactly the supported use case of smach.
Alternatively, it is possible, but discouraged by the Panda developers, to run one's own mainloop as described at http://www.panda3d.org/forums/viewtop... . So, I may have to use that approach as a last resort and let smach run the program's mainloop. Nevertheless, I'd prefer to use Panda in the style that the Panda developers promote. This would also facilitate using smach within other GUI programs that also assume control of the mainloop.